简体   繁体   English

403 禁止在 ubuntu 中使用 nginx

[英]403 forbidden of nginx in ubuntu

I have read beginner's guide of nginx :我已经阅读了 nginx 的初学者指南

server {
    location / {
        root /data/www;
    }

    location /images/ {
        root /data;
    }
}

http://localhost/images/example.png -> /data/images/example.png http://localhost/images/example.png -> /data/images/example.png

http://localhost/some/example.html -> /data/www/some/example.html http://localhost/some/example.html -> /data/www/some/example.html

So my nginx configuration:所以我的nginx配置:

 server {
            listen 443;
            server_name localhost;
            ssl on;
            ssl_certificate /home/attolee/sslkey/example.crt;
            ssl_certificate_key /home/attolee/sslkey/example.key;
            ssl_session_timeout 5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
            ssl_prefer_server_ciphers on;

            location / {
                    root /home/attolee;
                    index index.html;
            }

            location /hi/ {
                    root /home/attolee;
                    index hi.html;
            }
   }

I want我想要

  1. https://host/ access to /home/attolee/index.html, https://host/访问/home/attolee/index.html,
  2. https://host/hi/ access to /home/attolee/hi/hi.html, https://host/hi/访问/home/attolee/hi/hi.html,

Now 1 work, 2 failed, 403 forbidden.现在 1 个工作,2 个失败,403 禁止。

error log tells me is 13: Permission denied .错误日志告诉我是13: Permission denied

So I check own and group of /home/attolee and /home/attolee/hi/, as well as hi.html.所以我检查自己和组的/home/attolee 和/home/attolee/hi/,以及hi.html。

drwxr-xr-x  6 attolee attolee 4096 Nov  2 17:08 attolee/
drw-rw-rw- 2 root    root    4096 Nov  2 17:12 hi/
-rw-rw-rw- 1 root    root      24 Nov  2 17:12 hi.html

then check the nginx process USER property using htop is root.然后使用 htop 检查 nginx 进程 USER 属性是 root。

how to fix this?如何解决这个问题?

First, in your example you should do this:首先,在您的示例中,您应该这样做:

root /home/attolee;
index index.html hi.html
location / {
         try_files $uri $uri/ =404;  
}

Second, You don't need to run nginx as root.其次,您不需要以 root 身份运行 nginx。 In the nginx.conf you can change this to www-data for example.例如,在 nginx.conf 中,您可以将其更改为 www-data。 You have to move /home/hi inside /home/attolee/ and set /home/attolee with the correct owner.您必须将 /home/hi 移动到 /home/attolee/ 中,并将 /home/attolee 设置为正确的所有者。

i had this problem, for me problem was about nginx config in我有这个问题,对我来说问题是关于 nginx 配置

/etc/nginx/sites-available

My wrong was, I had defined some unnamed locations of files and folders.我的错误是,我定义了一些未命名的文件和文件夹位置。 so I edited the location and problem begin solved.所以我编辑了位置并开始解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM