Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
$remote_addr导致index.php不重写_Php_Wordpress_Nginx - Fatal编程技术网

$remote_addr导致index.php不重写

$remote_addr导致index.php不重写,php,wordpress,nginx,Php,Wordpress,Nginx,我正在用PHP-FPM和Nginx主持一个Wordpress博客。一个月前,我修改了网页的Nginx配置文件,如果$document_root中存在一个名为maintenance.html的文件,则返回代码503(并显示它) 以下是我目前撰写的相关章节: location / { # if you're just using wordpress and don't want extra rewrites # then replace the word @rewrites with /index.

我正在用PHP-FPM和Nginx主持一个Wordpress博客。一个月前,我修改了网页的Nginx配置文件,如果$document_root中存在一个名为maintenance.html的文件,则返回代码503(并显示它)

以下是我目前撰写的相关章节:

location / {
# if you're just using wordpress and don't want extra rewrites
# then replace the word @rewrites with /index.php
#   try_files $uri $uri/ @rewrites;
    try_files $uri $uri/ /index.php;
    index index.php;

    # site goes down for maintenance if maintenance.html exists in document_root
    if (-f $document_root/maintenance.html) {
        set $maint on;
    }

     # skip specific IP's (this is causing index.php to not rewrite for these IPs)
    if ($remote_addr ~ (1.2.3.4|ano.ther.ip.address)) {
        set $maint off;
    }

    if ($maint = on) {
        return 503;
    }

    location /maintenance {
    }
}
昨天,我注意到博客有问题。经过一些调查,我发现index.php没有被重写。当时,我让上面的部分写得有点不同。具体来说,如果$document\u root/maintenance.html存在并且$remote\u addr=!1.2.3.4(其中1.2.3.4是我的家庭IP),站点有效地处于维护模式。然而,事实证明index.php并没有被重写来处理来自非1.2.3.4的IP的任何请求。通过将if语句修改为上面的编写方式,index.php可以正确地重写来自非1.2.3.4的任何IP的任何请求


由于这些都与PHP重写无关,我不知道为什么会发生这种情况,我希望其他人知道原因。

尝试不同的模式
if($remote\u addr~'^1.2.3'.4$^5.6'.7'.8$)
显示完整的服务器块