Nginx 用户认证
2017-06-14 17:47
218 查看
[root@LHQ www]# cd /usr/local/nginx/conf/vhosts/
[root@LHQ vhosts]# ls
default.conf test.conf
[root@LHQ vhosts]# vim test.conf
将配置文件改为:
server
{
listen 80;
server_name www.test.com;
index index.html index.htm index.php;
root /data/www;
location ~ .*admin\.php$ {
auth_basic "aminglinux auth";
auth_basic_usre_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_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
需要创建 /usr/local/nginx/conf/.htpasswd文件,Nginx没有这样的工具,需要用Apache的那个生成密码的工具htpasswd.
有两种方法:
(1)使用yum安装
#yum install httpd
(2)之前手动安装编译过Apache
[root@LHQ vhosts]# ls /usr/local/apache2/bin/htpasswd
/usr/local/apache2/bin/htpasswd
使用这个工具创建密码文件
[root@LHQ vhosts]# htpasswd -c /usr/local/nginx/conf/.htpasswd qiangzi (第一次创建需要加上-c,后面就不需要了;qiangzi是新创建的用户)
New password: (输入新密码)
Re-type new password: (重新输入新密码)
Adding password for user qiangzi
查看文件:
[root@LHQ vhosts]# cat /usr/local/nginx/conf/.htpasswd
qiangzi:yYSTWnXZmvyCE(冒号后面是加过密的密码)
检查文件是否正确:
[root@LHQ vhosts]# /usr/local/nginx/sbin/nginx -t
如果没错,则执行:
[root@LHQ vhosts]# /etc/init.d/nginx reload
重新载入 Nginx: [确定]
用curl测试PHP解析:
[root@LHQ vhosts]# curl -x127.0.0.1:80 -uqiangzi:123456 www.test.com/admin.php
[root@LHQ vhosts]# ls
default.conf test.conf
[root@LHQ vhosts]# vim test.conf
将配置文件改为:
server
{
listen 80;
server_name www.test.com;
index index.html index.htm index.php;
root /data/www;
location ~ .*admin\.php$ {
auth_basic "aminglinux auth";
auth_basic_usre_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_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
需要创建 /usr/local/nginx/conf/.htpasswd文件,Nginx没有这样的工具,需要用Apache的那个生成密码的工具htpasswd.
有两种方法:
(1)使用yum安装
#yum install httpd
(2)之前手动安装编译过Apache
[root@LHQ vhosts]# ls /usr/local/apache2/bin/htpasswd
/usr/local/apache2/bin/htpasswd
使用这个工具创建密码文件
[root@LHQ vhosts]# htpasswd -c /usr/local/nginx/conf/.htpasswd qiangzi (第一次创建需要加上-c,后面就不需要了;qiangzi是新创建的用户)
New password: (输入新密码)
Re-type new password: (重新输入新密码)
Adding password for user qiangzi
查看文件:
[root@LHQ vhosts]# cat /usr/local/nginx/conf/.htpasswd
qiangzi:yYSTWnXZmvyCE(冒号后面是加过密的密码)
检查文件是否正确:
[root@LHQ vhosts]# /usr/local/nginx/sbin/nginx -t
如果没错,则执行:
[root@LHQ vhosts]# /etc/init.d/nginx reload
重新载入 Nginx: [确定]
用curl测试PHP解析:
[root@LHQ vhosts]# curl -x127.0.0.1:80 -uqiangzi:123456 www.test.com/admin.php
相关文章推荐
- nginx添加用户认证
- LNMP - nginx用户认证
- nginx通过用户和密码来实现认证功能
- Nginx安装、默认虚拟主机 、Nginx用户认证、Nginx域名重定向
- Nginx实战之让用户通过用户名密码认证访问web站点
- Nginx安装、默认虚拟主机、Nginx用户认证、Nginx域名重定向
- nginx配置用户认证
- nginx让用户通过用户名密码认证访问web页面
- 12.6 Nginx安装 - 12.7 默认虚拟主机 - 12.8 Nginx用户认证 - 12.9 Nginx域名重定向
- nginx用户认证配置( Basic HTTP authentication)及认证原理和实现
- nginx的IP访问控制及用户认证
- Nginx安装、默认虚拟主机、用户认证、nginx中PHP解析
- Nginx用户认证配置方法详解(域名/目录)
- Nginx介绍、Nginx安装、默认虚拟主机、用户认证、nginx中PHP解析
- nginx让用户通过用户名密码认证访问web页面
- nginx服务做用户认证和基于域名的虚拟主机
- Nginx之让用户通过用户名密码认证访问web站点
- Nginx用户认证配置方法(域名/目录)详解
- nginx添加用户认证
- 启动Nginx目录浏览功能及 让用户通过用户名密码认证访问web站点