Nginx设置URL用户登陆认证

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuxile/article/details/79204373
1.创建用户名密码文件
htpasswd -b -c /usr/local/nginx/conf/passwd.db myuser 123456
会在/usr/local/nginx/conf/passwd.db文件中生成用户名和加密的密码:
myuser:YlmaHlkJnzhxG
2.nginx增加auth_basic和auth_basic_user_file两项配置:
location /screen {
	auth_basic "secret";
	auth_basic_user_file /usr/local/nginx/conf/passwd.db;
	proxy_pass http://my.serverpool.com;
	proxy_set_header   Host    $host:$server_port;
	proxy_set_header   X-Real-IP   $remote_addr; 
	proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
}
3.重启nginx
pkill -9 nginx
./nginx

猜你喜欢

转载自blog.csdn.net/xuxile/article/details/79204373
今日推荐