CodexBloom - Programming Q&A Platform

Nginx 1.22.0 scenarios to Serve Static Files with '403 Forbidden' on CentOS 8 Stream

👀 Views: 4634 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-12
nginx centos selinux

I'm upgrading from an older version and I'm stuck on something that should probably be simple. I'm working with a '403 Forbidden' behavior when trying to serve static files with Nginx 1.22.0 on a CentOS 8 Stream server. The Nginx configuration seems correct, and I've triple-checked the file permissions. I have the following block in my Nginx configuration: ```nginx server { listen 80; server_name example.com; location / { root /var/www/html; index index.html; } } ``` The directory structure is as follows: ``` /var/www/html/ ├── index.html ├── images/ │ └── logo.png ``` I've confirmed that the `index.html` file exists in `/var/www/html` and I've set the permissions using: ```bash sudo chmod -R 755 /var/www/html ``` Additionally, the SELinux context is set to 'httpd_sys_content_t': ```bash sudo chcon -R -t httpd_sys_content_t /var/www/html ``` However, when I try to access `http://example.com/`, I still get a '403 Forbidden' behavior. I've looked through the Nginx behavior logs and found the following entry: ``` 2023/10/12 12:00:00 [behavior] 12345#0: *1 directory index of "/var/www/html/" is forbidden, client: 192.168.1.1, server: example.com, request: "GET / HTTP/1.1", host: "example.com" ``` I've also tried setting the `autoindex` directive to `on` to see if that would change anything: ```nginx location / { root /var/www/html; index index.html; autoindex on; } ``` But that did not resolve the scenario. Any thoughts on what could be going wrong here? I suspect it might be an SELinux scenario or perhaps a misconfiguration in the Nginx settings. I'm coming from a different tech stack and learning Nginx.