CodexBloom - Programming Q&A Platform

Nginx 1.18 on CentOS 8 - 403 Forbidden scenarios when Accessing Static Files in Docker

πŸ‘€ Views: 56 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-09
nginx docker centos

I'm having trouble with I've hit a wall trying to I'm relatively new to this, so bear with me..... I'm running an Nginx server in a Docker container on CentOS 8, trying to serve some static files located in `/usr/share/nginx/html`. However, I keep getting a `403 Forbidden` behavior when I attempt to access these files via my web browser. I mapped the host directory to the container with the following Docker run command: ```bash docker run -d -p 80:80 -v /path/to/host/html:/usr/share/nginx/html --name my-nginx nginx:1.18 ``` I've confirmed that the static files are present in the `/usr/share/nginx/html` directory inside the container. However, when I check the Nginx behavior log, I see entries like: ``` 2023/10/10 12:15:32 [behavior] 7#7: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 192.168.1.10, server: localhost, request: "GET /index.html HTTP/1.1", host: "localhost" ``` I attempted to adjust the Nginx configuration to explicitly set the `root` directive and added `autoindex on;`, but that didn't resolve the scenario. Here’s the relevant part of my `nginx.conf`: ```nginx server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html; autoindex on; } } ``` I've also checked the file permissions on both the host and the container. The files are owned by `nginx:nginx` in the container, and I've set the permissions to `755` on the host directory. Does anyone have suggestions on what could be causing this `403 Forbidden` behavior? Could it be related to SELinux or something else specific to CentOS that I might be missing? Any help would be greatly appreciated! Has anyone else encountered this? This is for a web app running on Windows 10. Any help would be greatly appreciated! I'm on macOS using the latest version of Nginx. Any advice would be much appreciated.