【发布时间】:2014-02-12 22:35:45
【问题描述】:
我已经在 Amazon Linux AMI 上设置了 Nginx。默认 Nginx 页面加载正常:
http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com/
而nginx.conf中的server语句代码为:
server {
listen 80;
#server_name localhost;
server_name ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
因此,通过将 server_name 更改为,在我的域中对其进行了测试
server_name samplesite.com;
通过浏览器访问也可以正常工作
http://samplesite.com/
但是当我把“location/root”改成不同的路径后,就不行了,这里是nginx.conf服务器语句:
server {
listen 80;
server_name samplesite.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /home/ec2-user/samplesite.com/public_html; <--- Changed here!!!
index index.html index.htm;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
唯一改变的部分是
root /home/ec2-user/samplesite.com/public_html;
这是因为我希望站点目录位于“ec2-user”下。我检查了默认的 Nginx 目录文件所有者在
/usr/share/nginx/html
但一切都归“root”所有,据我所知,不建议使用 root 帐户,应该使用不同的用户帐户:
drwxr-xr-x 2 root root 4096 Jan 22 01:14 .
drwxr-xr-x 3 root root 4096 Jan 22 01:14 ..
-rw-r--r-- 1 root root 3696 Nov 21 22:04 404.html
-rw-r--r-- 1 root root 3738 Nov 21 22:04 50x.html
-rw-r--r-- 1 root root 3770 Nov 21 22:04 index.html
-rw-r--r-- 1 root root 370 Nov 21 22:04 nginx-logo.png
所以想改用“ec2-user”(或者我应该为网络创建一个新帐户?)。所以我的问题是,该目录是否必须由“root”拥有才能工作?因为如果目录所有者是/home/ 目录下的“ec2-user”,我似乎无法使网站可访问。
【问题讨论】:
-
您可以粘贴访问日志中的相关部分吗?你的 nginx 在什么 euid 下运行?
-
Nginx 以 nginx 用户运行
标签: amazon-web-services nginx amazon-ec2