location ~ .*admin\.php$ {
auth_basic "weifenglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
yum install -y httpd (安装 htpasswd命令)
类似apache创建密码文件
htpasswd -c /usr/local/nginx/conf/.htpasswd weifeng
New password:justdoit
增加新用户
htpasswd /usr/local/nginx/conf/.htpasswd weifeng1
New password:justdoit
/usr/local/nginx/sbin/nginx -t
/etc/init.d/nginx reload
刷新页面需要用户认证
实例配置:
server {
listen 80;
server_name hk_grafana*******.cn;
location / {
auth_basic "grafana auth";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
proxy_pass http://172.********:32102/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#client_max_body_size 100m;
}
}
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。