nginx配置auth_basic认证

nginx配置auth_basic认证

windows

1、下载 httpd 下载地址: https://www.apachelounge.com/download/
2、生成密码:打开cmd,进入到 Apache24\bin后 html htpasswd.exe -c G:\nginx\nginx-1.14.2\conf\.htpasswd user
其中: G:\nginx\nginx-1.14.2\conf为你自己的nginx位置
user为用户名, 可以根据自己的情况定义
输入完成后打回车后输入密码, 再次输入密码即可;
3、找到nginx.conf文件,在需要做安全认证的地方添加

	auth_basic "Restricted Area";
	auth_basic_user_file G:/nginx/nginx-1.14.2/conf/.htpasswd;

nginx配置auth_basic认证_第1张图片
配置完成后重启nginx;

linux

yum install httpd-tools -y

安装完成后

htpasswd -c /path/to/password-file username

配置nginx

        location / {
            root   html;
            index  index.html index.htm;
			# 开启功能模块,关闭为off
			auth_basic on;
			# 指定密码配置文件
			auth_basic_user_file home/web/auth/auth_basic_user_file;
			# 验证通过后 跳转的相关路径
			proxy_pass   http://127.0.0.1:8080;
        }

你可能感兴趣的:(nginx,nginx,运维)