Nginx配置——用户认证
2017-01-01 20:07
417 查看
## 生成密码文件
[root@localhost ~]# /usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/.htpasswd wyy
New password:
Re-type new password:
Adding password for user wyy
解释说明:
借助于apache的工具htpasswd实现生成用户,密码
-c 新建一个文件指定目录(...nginx/conf)
## 使用验证
[root@localhost ~]# vim /usr/local/nginx/conf/vhosts/test.conf
location ~ .*admin\.php$ { # 所匹配的需要身份认证,这也可以是一个目录(目录就不用加php解析了)
auth_basic "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;
}
解释说明:
红色字体不加的话,它就会直接下载了.php的那个文件,说明了.php并没有真正地解析。
## 检查语法并重启
[root@localhost vhosts]# /usr/local/nginx/sbin/nginx -t
[root@localhost vhosts]# /etc/init.d/nginx reload
## 测试
[root@localhost vhosts]# curl -x127.0.0.1:80 www.test.com/admin.php
<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.6.2</center>
</body>
</html>
解释说明:
401表示输入用户名密码认证
[root@localhost vhosts]# curl -uwyy:123456 -x127.0.0.1:80 www.test.com/admin.php
解释说明:
显示出来的如果是php代码块,就说明php没有解析出来,显示的如果是html标签就是解析出来了。
[root@localhost ~]# /usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/.htpasswd wyy
New password:
Re-type new password:
Adding password for user wyy
解释说明:
借助于apache的工具htpasswd实现生成用户,密码
-c 新建一个文件指定目录(...nginx/conf)
## 使用验证
[root@localhost ~]# vim /usr/local/nginx/conf/vhosts/test.conf
location ~ .*admin\.php$ { # 所匹配的需要身份认证,这也可以是一个目录(目录就不用加php解析了)
auth_basic "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;
}
解释说明:
红色字体不加的话,它就会直接下载了.php的那个文件,说明了.php并没有真正地解析。
## 检查语法并重启
[root@localhost vhosts]# /usr/local/nginx/sbin/nginx -t
[root@localhost vhosts]# /etc/init.d/nginx reload
## 测试
[root@localhost vhosts]# curl -x127.0.0.1:80 www.test.com/admin.php
<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.6.2</center>
</body>
</html>
解释说明:
401表示输入用户名密码认证
[root@localhost vhosts]# curl -uwyy:123456 -x127.0.0.1:80 www.test.com/admin.php
解释说明:
显示出来的如果是php代码块,就说明php没有解析出来,显示的如果是html标签就是解析出来了。
相关文章推荐
- nginx配置用户认证
- nginx防盗链、访问控制、PHP解析、服务器代理
- Nginx安装、默认虚拟主机、用户认证、nginx中PHP解析
- Nginx安装,Nginx默认虚拟主机,Nginx用户认证,Nginx重定向
- nginx用户认证与htpasswd命令
- nginx启动脚本和配置文件
- Nginx编译安装
- Nginx在Windows上启动、停止的命令
- nginx配置详解
- NGINX CENTOS 6.5 安装
- Centos7+Nginx负载均衡(Load Balance)配置详情介绍 推荐
- Centos7+Nginx+Keepalived实现Apache服务的高可用&负载均衡 推荐
- 架构设计:负载均衡层设计方案(2)——Nginx安装
- 在Windows Azure 安装Nginx虚拟机-篇章1-安装Nginx准备系列工作!
- win下nginx+php
- nginx超时转发机制
- 升级CentOS6.5内核,开启Nginx的fastopen和reuseport特性
- nginx配置
- Nginx出现413 Request Entity Too Large错误解决方法
- nginx 配置多目录