2017-04-13 194 views
1

我想反向代理我的NodeJS通过NGINX后端,但我不断收到403禁止错误,nginx的记录为NGINX反向代理和静态文件

[error] 10#10: *1 directory index of "/usr/share/nginx/html/" is forbidden, 
client: 172.20.0.1, server: localhost, request: "GET/HTTP/1.1", 
host: "localhost:8888 

我的服务器模块配置:

server { 

    charset utf8; 
    listen 80 default_server; 

    location/{ 
     proxy_pass http://localhost:5000; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_cache_valid 200 1s; 
    } 

    location /assets/ { 
     expires 30d; 
     add_header Cache-Control "public"; 
     root /usr/share/nginx/html/; 
     try_files $uri =404; 
    } 
} 

经过一番研究,似乎它可能与NGINX identifying / as a query for a directory listing有关,并且很可能会要求我添加index index.html来解决问题(它没有)。我的配置也匹配that presented by the official NGINX configurations反向代理。

有没有人有一个想法如何解决这个问题?

任何帮助将不胜感激! 干杯:)

+0

我不明白'localhost:8888'部分的错误信息。您还应该使用'nginx -T'测试您的配置。 –

+0

localhost:8888是我从中调用请求的主机。我不相信它与它有任何关系,但我的设置在docker中运行(请参阅此[docker-compose文件](https://github.com/futureboyHQ/website/blob/feature/6/docker/docker) -compose.yml))。尽管它没有提供更多信息,但您可以在这里找到'nginx -T'打印输出(https://pastebin.com/HHAk1Kba)。 –

回答

1

它使用服务器localhost这是其他server块。

您问题中的server块是默认服务器,但另一个块具有明确的server_name localhost语句,该语句优先。

您应该删除另一个服务器块,以便只有一个服务器块,它将始终使用。

问题文件位于/etc/nginx/conf.d/default.conf

server块的选择在this document中解释。

+0

太棒了!这绝对解决了我的问题!我通过添加'RUN RM -f的/ etc/nginx的/ conf.d/default.conf'命令到nginx的dockerfile施加的溶液。干杯:D –