>_ IzzyLab

Hands-on task

This task is step 12 of the course “nginx basics”

The landing page styles return 403

medium~5 min

The landing page from /srv/landing opens at http://localhost/, but unstyled: the stylesheet /css/site.css answers 403 Forbidden. nginx is running, the config is valid. Sort out the permissions and fix it so the styles are served with status 200. Don't hand out "write for everyone" permissions.

What you'll practise:
  • file permissions
  • chmod
  • nginx 403
  • x bit on a directory
  • error.log

Topic breakdown

The nginx worker doesn't run as root but as an unprivileged user (www-data), and sees the site's files with the "others" permissions. To serve a file it needs the r bit on the file itself and the x bit on every directory along the path — without x you can't "enter" a directory, even if the file inside is readable. That's why a 403 can hit not the whole site but a single section: the home page is served, while files in a subdirectory with 700 aren't. error.log names the cause and the path (Permission denied), and the cure is a targeted chmod, without handing out 777.

What's checked

  1. the styles are served with status 200
  2. the home page still opens
  3. write for everyone isn't opened

What it looks like