NGINX反向代理&;静态文件

NGINX反向代理&;静态文件,nginx,server,reverse-proxy,Nginx,Server,Reverse Proxy,我想通过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;

我想通过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;
  }
}
在做了一些研究之后,它似乎与这个问题有关,并且很可能需要我添加
index.html
来解决这个问题(它没有)。我的配置也与反向代理匹配

有人知道如何解决这个问题吗

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

它正在使用服务器
localhost
,这是另一个
服务器

问题中的
server
块是默认服务器,但另一个块有一个显式的
server\u name localhost
语句,该语句优先

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

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


选择
server
块的说明见。

我不理解错误消息的
localhost:8888
部分。您还应该使用
nginx-T
localhost:8888是我调用请求的主机。我不相信这与它有任何关系,但我的设置在docker中运行(参见此)。另外,尽管它没有提供更多的信息,你可以找到
nginx-t
打印输出。太棒了!这绝对解决了我的问题!我通过向nginx dockerfile添加
runrm-f/etc/nginx/conf.d/default.conf
命令来应用您的解决方案。干杯:D