使用Nginx和PHP-FPM在Wordpress上访问直接文件时找不到文件

问题描述 投票:0回答:1

我正在使用此配置在Nginx 1.12.2和PHP-fpm上运行Wordpress:

server {
    listen 80;
    server_name myweb.com;
    return 301 $scheme://www.myweb.com$request_uri;
}

server {
    root /var/www/myweb/public_html;
    index index.php index.html index.htm;
    server_name www.myweb.com;

    listen 80;
    location / {
        #mod-rewrite to enable friendly url (wp permalink)
        try_files $uri $uri/ /index.php?$args;
    }

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). Keep logging the 
    # requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~ /\. {
        deny all;
    }
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
    location ~ \.php$ {
        try_files $uri =404;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

它工作正常,但直接执行.php文件时出错。

screenshot

ON | OFF开关直接访问文件: http://www.myweb.com/wp-content/plugins/myplugin/setStatus.php

并返回404文件未找到。我的cron尝试访问插件目录下的.php文件时遇到的错误相同。

如何正确设置?我需要你的导游。

感谢你们!

php wordpress nginx
1个回答
0
投票

据我所知,所有工作,但直接链接到任何PHP文件。我建议将您的php位置块切换为类似于以下内容:

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_hide_header "X-Powered-By";
        fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
    }

不要忘记在测试之前重新加载nginx。

有关HTTP_PROXY参数及其使用原因的更多信息

© www.soinside.com 2019 - 2024. All rights reserved.