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” 博客,转载请与作者联系!
环境架构: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” 博客,转载请与作者联系!
相关文章推荐
- 从nginx获取css无法解析的问题
- Centos下安装nginx rpm包
- nginx安全
- nginx安全
- nginx js、css多个请求合并为一个请求(concat模块)
- nginx.conf配置文件的基本详解
- Nginx重写规则指南 转
- nginx做rails项目web服务器缓存配置方法
- Ubuntu下安装Nginx
- nginx服务配置---php服务接入
- Nginx和lvs在负载均衡方面的对比
- nginx php-fpm 输出php错误日志
- Nginx代码风格图示
- Centos安装nginx
- nginx---别名(alias)在ci框架的应用
- Debian 7/Ubuntu14.04 LNMP环境搭建
- wordpress 图片裁剪问题处理
- nginx+ngrok的配置
- Nginx配置文件nginx.conf中文详解(汇总)
- nginx的安装及配置