我已经在Amazon Linux AMI上设置了Nginx。默认Nginx的页面加载罚款:Nginx用户帐户用于Amazon EC2 EC2上的Web目录AMI
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 samplesite.com;
它也可以通过访问使用浏览器正常工作
http://samplesite.com/
但是,当我改变了“位置/根”到不同的路径,这是行不通的,而这里是nginx.conf server语句:
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账号,应使用不同的用户帐户拥有:
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”代替(或者我应该为web创建一个新帐户?)。所以我的问题是,目录必须由“root”拥有才能工作?因为如果目录所有者是/home/
目录下的“ec2-user”,我似乎无法访问该网站。
你可以粘贴访问日志中的相关部分吗?你的nginx运行于什么euid? –
Nginx以nginx用户身份运行 – user702300