Exercise: SELinux on web content
Tasks
- Create
/srv/web/index.htmlwith some text. - Configure nginx to serve
/srv/webon port 80. - Fix SELinux without disabling it and without
chcon. - Prove the page is served with 200.
Verify
ls -dZ /srv/web # httpd_sys_content_t
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1/
getenforce # Enforcing
Solution
sudo mkdir -p /srv/web && echo 'hello' | sudo tee /srv/web/index.html
sudo tee /etc/nginx/conf.d/lab.conf >/dev/null <<'EOF'
server { listen 80 default_server; server_name _; root /srv/web; }
EOF
sudo semanage fcontext -a -t httpd_sys_content_t '/srv/web(/.*)?'
sudo restorecon -Rv /srv/web
sudo nginx -t && sudo systemctl enable --now nginx
If 403 persists: ausearch -m AVC -ts recent (SELinux) or ls -la /srv /srv/web (POSIX permissions).