Forest Notes

Tips, tricks, cheatsheets


Project maintained by iamzaychik Hosted on GitHub Pages — Theme by mattgraham

Nginx Password auth for IP

2019-04-15


Enable basic auth:

server
{
	# Title for auth window
    auth_basic "Closed site";
    # Path to file with user:password in MD5
    auth_basic_user_file /etc/nginx/users;
}

$ cat /etc/nginx/users
john:$apr1$IHaD0/..$N9ne/Bqnh8.MyOtvKU56j1

Disable basic auth for some IPs (satisfy module):

server
{
    satisfy any;
    allow 203.0.113.1;
    allow 203.0.113.2;
    deny all;
    auth_basic "Closed site";
    auth_basic_user_file /etc/nginx/users;
}

Source