Nginx使用htpasswd创建用户认证
Linux下执行,生成认证文件/usr/local/nginx/conf/htpasswd/cacti
/usr/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/cacti addcn
配置nginx文件,/usr/local/nginx/conf/nginx.conf
# cacti
location /cacti/ {
auth_basic "Restricted";
auth_basic_user_file /usr/local/nginx/conf/htpasswd/cacti;
}
值得注意的是 ,如果对 /private/目录做了限制,那么/private/filename.php 是不生效的,因为后面的正则表达式又对php进行了fastcgi转发。
解决办法就是:单独把private目录下的php文件限制也写到规则里面,而且在php文件解析的规则之前。
#deny private
location /private/ {
allow 222.222.222.35;
allow 192.168.1.0/249;
deny all;
}
#deny private/filename.php
location ~ ^/private/.*\.php$
{
allow 222.222.222.35;
allow 192.168.1.0/249;
deny all;
}
#php
location ~ .*\.php?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
/usr/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/cacti addcn
配置nginx文件,/usr/local/nginx/conf/nginx.conf
# cacti
location /cacti/ {
auth_basic "Restricted";
auth_basic_user_file /usr/local/nginx/conf/htpasswd/cacti;
}
值得注意的是 ,如果对 /private/目录做了限制,那么/private/filename.php 是不生效的,因为后面的正则表达式又对php进行了fastcgi转发。
解决办法就是:单独把private目录下的php文件限制也写到规则里面,而且在php文件解析的规则之前。
#deny private
location /private/ {
allow 222.222.222.35;
allow 192.168.1.0/249;
deny all;
}
#deny private/filename.php
location ~ ^/private/.*\.php$
{
allow 222.222.222.35;
allow 192.168.1.0/249;
deny all;
}
#php
location ~ .*\.php?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23