我正在使用此配置在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文件时出错。
ON | OFF开关直接访问文件:
http://www.myweb.com/wp-content/plugins/myplugin/setStatus.php
并返回404文件未找到。当我的cron尝试访问插件目录下的.php文件时,我得到了同样的错误。
如何正确设置? 我需要你的导游。
谢谢你们,伙计们!
答案 0 :(得分: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参数的更多信息及其使用原因