nginx 配置用户认证

nginx 配置用户认证有两种方式:
1.auth_basic 本机认证,由ngx_http_auth_basic_module模块实现。
2.auth_request,由ngx_http_auth_request_module模块实现。

第一种方式:
yum -y install httpd-tools //安装 htpasswd 工具
htpasswd -c /etc/nginx/.passwd-www www //生成用户登录的认证文件
chmod 600 /etc/nginx/.passwd-www
配置nginx本地认证:
server {
    listen       80;
    server_name  www.imcati.com;
    
    auth_basic "User Authentication";
    auth_basic_user_file /etc/nginx/.passwd-www;
location / { root /usr/share/nginx/html; index index.html; } }
加载配置: nginx -s reload


猜你喜欢

转载自www.cnblogs.com/imcati/p/11674682.html