我在Amazon Linux AMI上设置了NGINX。默认的nginx页面加载正常:
http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com/
和nginx.conf中的服务器语句代码是:
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/
但是,当我将"位置/根"更改为其他路径时,它不起作用,这是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-用户"下。我在
上检查了默认的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-用户"(或者我应该为Web创建一个新帐户?)。所以我的问题是,目录必须由" root"拥有才能工作?因为如果目录所有者是/home/
目录中的" EC2-用户",我似乎无法访问该网站。
确保/home/ec2-user/samplesite.com/public_html
具有755个权限。
使其工作的另一种方法是将NGINX Works过程作为ec2-user
运行。在nginx.conf文件中,具有这样的内容:
user ec2-user;
worker_processes 1;
确保/home/ec2-user/samplesite.com/public_html
下的每个人都有所有者。集团ec2-user
chown -R ec2-user.ec2-user /home/ec2-user/samplesite.com/public_html
希望它有帮助。