>_ IzzyLab

Hands-on task

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

Lock down /admin with basic auth

medium~10 min

The admin panel at http://localhost/admin/ is open to the whole world. Lock it down with HTTP basic auth: user admin, password izzylab. The rest of the site must stay public.

What you'll practise:
  • nginx
  • http basic auth
  • htpasswd
  • location
  • 401

Topic breakdown

HTTP Basic Auth is the simplest mechanism: the server responds with 401 until the client sends a login and password in the header. Passwords are stored not in plain text but in an htpasswd file as a login plus a hash, created by the utility of the same name. In nginx, protection is applied selectively to a specific location block via the auth_basic and auth_basic_user_file directives, so you can lock down a single path while leaving the rest of the site public.

What's checked

  1. /admin/ requires a password
  2. credentials admin/izzylab open /admin/
  3. the public page is accessible without a password

What it looks like