您的位置:首页 > 运维架构 > Nginx

nginx的高级配置(1)——为某个虚拟主机添加用户验证

2015-11-30 16:30 811 查看
版本:centos6.5 ; mysql-5.6.26 ;nginx-1.6.3 ;php-5.4.37
环境架构:LNMP
1.配置第二个虚拟主机
可以在nginx.conf 加一行
include vhosts/*.conf;
这样,我们就可以在 /usr/local/nginx/conf/vhosts目录下创建虚拟主机配置文件了。
#mkdir /usr/local/nginx/conf/vhosts
#cd !$
#vim 111.conf // 加入
server

server
{
listen 80;
server_name 192.168.137.100;
index index.html index.htm index.php;
root /data/www;
location ~ .*admin\.php$ {
auth_basic "xiayun 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;

}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}

}
2.用户认证
首先需要安装apache,可以使用yum install httpd 安装
生成密码文件,创建用户
htpasswd -c /usr/local/nginx/conf/htpasswd test
添加test用户,第一次添加时需要加-c参数,第二次添加时不需要-c参数
总结:用户认证可以使用户登录某个路径时进行用户认证,提高保密度

本文出自 “echo xiayun” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: