Wednesday, July 22, 2009

nginx basic auth (htpasswd)

Nginx supports basic auth (ngx_http_auth_basic_module)

directives:
auth_basic [|off]
auth_basic_user_file path/to/file

htpasswd file format:
# comment
login:password

Command htpasswd should be used with option -d , because nginx supports crypt() algorithm only.

Example:
htpasswd -c -d /etc/nginx/htpasswd asalnikov

nginx.conf part:
location /
{
auth_basic "closed site";
auth_basic_user_file /etc/nginx/htpasswd;
...
}

1 comment:

  1. If you use passenger, make sure to add passenger_enabled on; inside the location block.

    ReplyDelete