【发布时间】:2017-09-09 19:14:37
【问题描述】:
我想通过 NGINX 反向代理我的 NodeJS 后端,但我不断收到 403 禁止错误,由 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 的反向代理。
有人知道如何解决这个问题吗?
任何帮助将不胜感激! 干杯:)
【问题讨论】:
-
我不明白错误消息中的
localhost:8888部分。您还应该使用nginx -T测试您的配置 -
localhost:8888 是我从中调用请求的主机。我不相信这与它有任何关系,但我的设置在 docker 中运行(参见docker-compose file)。此外,虽然它没有提供更多信息,但您可以找到
nginx -T打印输出 here。
标签: nginx server reverse-proxy