Reputation: 2028
I would like to reverse proxy my NodeJS backend through NGINX, but I keep getting the 403 Forbidden Error, logged by NGINX as
[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
My configuration for the server block:
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;
}
}
After doing some research, it seems like it may be related to 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 for reverse proxies.
Does anyone have an idea how to solve this?
Any help would be greatly appreciated! Cheers :)
Upvotes: 1
Views: 345
Reputation: 49802
It's using server localhost
which is the other server
block.
The server
block in your question is the default server, but the other one has an explicit server_name localhost
statement, which takes precedence.
You should probably remove the other server block, so that there is only one server block, which will always be used.
The problem file is located at /etc/nginx/conf.d/default.conf
.
Selection of server
block is explained in this document.
Upvotes: 1