1

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 :)

2
  • I don't understand the localhost:8888 part of the error message. You should also test your configuration using nginx -T Commented Apr 13, 2017 at 16:26
  • The localhost:8888 is the host from which I am calling the request. I don't believe it has anything to do with it, but my setup runs in docker (see this docker-compose file). Also albeit it doesn't give much more info, you can find the nginx -T printout here. Commented Apr 13, 2017 at 21:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great! This definitely solved my issue! I applied your solution by adding a RUN rm -f /etc/nginx/conf.d/default.conf command to an nginx dockerfile. Cheers :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.