Interview Prep/Linux/Permissions, ownership, SELinux and mounts

nginx returns 403 and logs `open() "/srv/www/index.html" failed (13: Permission denied)`, even after `chmod -R 777 /srv/www`.

IntermediateTroubleshootingPermissions, ownership, SELinux and mounts
Answer

Likely causes → SELinux is denying access because the files have the wrong context (default_t or user_home_t instead of httpd_sys_content_t), or a parent directory lacks x for nginx.

Diagnose →

getenforce
ls -Z /srv/www/index.html
sudo ausearch -m AVC -ts recent | grep nginx
namei -l /srv/www/index.html          # permissions on every path component

Fix →

sudo semanage fcontext -a -t httpd_sys_content_t '/srv/www(/.*)?'
sudo restorecon -Rv /srv/www
sudo chmod -R u=rwX,go=rX /srv/www    # undo the 777

Prevent → Use standard paths (/var/www) or register custom paths with semanage fcontext in config management.

All Linux questions Roadmap: Linux

More on Permissions, ownership, SELinux and mounts