NGINX 反向代理和静态文件
NGINX Reverse Proxying & Static Files
我想通过 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 and would most likely require me to add index index.html
to solve the issue (it didn't). My configuration also matches that presented by the official NGINX configurations 有关。
有人知道如何解决这个问题吗?
如有任何帮助,我们将不胜感激!
干杯:)
它正在使用另一个 server
块的服务器 localhost
。
你问题中的 server
块是默认服务器,但另一个有明确的 server_name localhost
语句,优先。
您可能应该删除另一个服务器块,这样就只有一个服务器块,它将始终被使用。
问题文件位于/etc/nginx/conf.d/default.conf
。
server
块的选择在 this document 中解释。
我想通过 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 and would most likely require me to add index index.html
to solve the issue (it didn't). My configuration also matches that presented by the official NGINX configurations 有关。
有人知道如何解决这个问题吗?
如有任何帮助,我们将不胜感激! 干杯:)
它正在使用另一个 server
块的服务器 localhost
。
你问题中的 server
块是默认服务器,但另一个有明确的 server_name localhost
语句,优先。
您可能应该删除另一个服务器块,这样就只有一个服务器块,它将始终被使用。
问题文件位于/etc/nginx/conf.d/default.conf
。
server
块的选择在 this document 中解释。