【问题标题】:Nginx user account used for web directory on EC2 with Amazon Linux AMI用于 EC2 上的 Web 目录和 Amazon Linux AMI 的 Nginx 用户账户
【发布时间】: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


【解决方案1】:

确保/home/ec2-user/samplesite.com/public_html 拥有 755 个权限。

另一种使其工作的方法是将 nginx 工作进程作为ec2-user 运行。在 nginx.conf 文件中是这样的:

user              ec2-user;
worker_processes  1;

确保/home/ec2-user/samplesite.com/public_html 下的所有内容都有 owner.group ec2-user

chown -R ec2-user.ec2-user /home/ec2-user/samplesite.com/public_html

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2015-03-19
    • 2011-12-28
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    相关资源
    最近更新 更多