本帖最后由 以谁为师 于 2015-6-19 09:11 编辑
需要注意的是,在这个location下也得加入php解析相关的配置,否则php文件无法解析
我的wecenter规则
[AppleScript] 纯文本查看 复制代码 location ~ .*admin.* {
allow 60.191.XX.XX;
deny all;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_index index.php;
}
try_files $uri $uri/ /index.php$is_args$args;
}
thinkphp规则,对包含admin字串进行url规则
[AppleScript] 纯文本查看 复制代码 location ~ .*admin.* {
index index.php index.html index.htm;
allow 60.191.0.1;
deny all;
if (!-e $request_filename)
{ rewrite ^/(.*)$ /index.php/$1;}
location ~ \.php {
include fastcgi.conf;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
}
ps 最后一条使用deny all;拒绝其他ip访问。也可以加入 web认证 ,使用 htpasswd建立密码。
[AppleScript] 纯文本查看 复制代码
location ~ .admin.php
{
#allow 1.1.1.1;
#allow 12.12.12.0/24;
#deny all;
auth_basic "Authorized users only";
auth_basic_user_file /usr/local/nginx/conf/auth/password.conf;
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
[AppleScript] 纯文本查看 复制代码 wordpress 后台密码保护 nginx
location ~ /wp-login\.php {
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
auth_basic "Restricted";
auth_basic_user_file htpasswd;
} |