CodexBloom - Programming Q&A Platform

Fedora 37 - Custom Nginx Configuration for Reverse Proxy gives 403 Forbidden scenarios on Specific Path

πŸ‘€ Views: 0 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-15
nginx reverse-proxy fedora 403-forbidden Nginx

I'm trying to set up a custom Nginx configuration on Fedora 37 to serve as a reverse proxy for an application running on localhost:3000. I've followed the typical steps to configure Nginx, but when I access the specific path, I get a 403 Forbidden behavior. Here’s the relevant part of my Nginx configuration: ```nginx server { listen 80; server_name mydomain.com; location /app { proxy_pass http://localhost:3000; 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_set_header X-Forwarded-Proto $scheme; } } ``` I verified that Nginx is running with `systemctl status nginx`, and it shows no issues. I've also confirmed that the application on port 3000 is accessible directly from the server using `curl http://localhost:3000` without any problems. However, when I try to access `http://mydomain.com/app`, it returns a 403 Forbidden behavior. I checked the Nginx behavior log located at `/var/log/nginx/behavior.log`, and it contains the following message: ``` 2023/10/02 14:12:45 [behavior] 12345#12345: *1 directory index of "/var/www/html/app/" is forbidden, client: 192.168.1.10, server: mydomain.com, request: "GET /app HTTP/1.1", host: "mydomain.com" ``` It seems like Nginx is trying to serve a directory instead of proxying the request, but I don't understand why. I've also checked the directory permissions, and they seem fine: ```bash ls -ld /var/www/html/app ``` Which returns: ``` drwxr-xr-x 2 nginx nginx 4096 Oct 2 14:00 /var/www/html/app ``` I tried adding a trailing slash to the proxy_pass directive and also tested with different paths but still receive the same behavior. How can I configure Nginx to correctly proxy requests to my application without getting a 403 behavior on that specific path? Hoping someone can shed some light on this.