即使在设置权限后,Nginx 403也被禁止

时间:2017-01-02 11:58:03

标签: django ubuntu nginx lets-encrypt

我想为我的域名获取Letsencrpyt SSL。部分过程是,在获得证书之前,需要对站点进行授权。

我创建了文件夹./well-known并运行了我被要求的命令,我得到了;

Nginx 403 forbidden.

我在nginx / 1.10.0(Ubuntu)

chown目录并授予它755但仍然相同。查看下面我目录中的权限。

namei -l /var/www/example.com/.well-known                      

 f: /var/www/example.com/.well-known
 drwxr-xr-x root   root /
 drwxr-xr-x root   root var
 drwxr-xr-x root   root www
 drwxr-xr-x cman sudo example.com
 drwxr-xr-x cman sudo .well-known

我还在working.html文件夹中创建了一个/.well-known文件,然后加载example.com/.well-known/working.html,我得到了同样的403 Forbidden。

Nginx.conf

 upstream kip_app_server {
   # fail_timeout=0 means we always retry an upstream even if it failed
   # to return a good HTTP response (in case the Gunicorn master nukes a
   # single worker for timing out).

    server unix:/var/www/example.com/src/run/trav.sock fail_timeout=0;
}

server {
      listen 80;
      server_name example.com www.example.com;

 location = /favicon.ico { access_log off; log_not_found off; }
 access_log /var/www/example.com/logs/access.log;
 error_log /var/www/example.com/logs/nerror.log;

 charset utf-8;

 client_max_body_size 75M;

  location /static/ {
       alias /var/www/example.com/src/static/;
   }

   location /media/ {
       alias var/www/example.com/src/media/;
  }

   location ~ /\.well-known {
       allow all;
       alias /var/www/example.com/.well-known/;
    }


    location / {
      include proxy_params;
       proxy_pass http://kip_app_server;
       #proxy_set_header X-Forwarded-Host $server_name;
      #proxy_set_header X-Real-IP $remote_addr;
   }
 }

1 个答案:

答案 0 :(得分:2)

如果您没有使用别名,您的代码就可以使用。

试试这个:

location ^~ /.well-known {
   allow all;
   alias /var/www/example.com/.well-known/;
}

或者这个:

location ^~ /.well-known {
    allow all;
    auth_basic off;
    alias /path/to/.well-known/;
}

当别名时,^是必需的。

这是Nginx特定的行为,它们执行匹配的方式。这里有关于匹配逻辑和警告的详细说明,令人困惑:https://github.com/letsencrypt/acme-spec/issues/221