Nginx Wordpress配置,主题目录中的PHP文件未传递给FastCGI


Nginx Wordpress Configuration, PHP file in theme directory is not passed to FastCGI

我是NGINX配置的新手,请耐心等待。以下是我的配置,适用于整个网站:

server {
listen ...;
server_name  funkyoslo.no;
#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;
location / {
    root   /usr/share/nginx/funkyoslo.webbr.org/html;
    index  index.php index.html index.htm;
    try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/funkyoslo.webbr.org/html/;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ '.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/funkyoslo.webbr.org/html/$fastcgi_script_name;
    include        fastcgi_params;
}
}

然而,我正在尝试加载文件/wp-content/themes/finkyoslo/load-songs.php,它给了我一个500内部服务器错误。我已经检查了错误日志,显然该文件根本没有传递给FastCGI。

我尝试添加以下块,但没有成功:

location ~ .*/wp-content/themes/funkyoslo/.*'.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/funkyoslo.webbr.org/html/wp-content/themes/funkyoslo/$fastcgi_script_name;
    include         fastcgi_params;
}

非常感谢您的帮助!

我不知道你的配置出了什么问题,但试一下,希望它能起作用,这是最小的配置。

备注

  • 删除了服务器块级别的索引,请检查链接以了解原因
  • 删除了服务器块级别的根,请检查链接以了解原因
  • 删除了php块级别的所有额外配置,通过试用,我意识到我只需要我写的那两个
  • http://添加到fastcgi_pass,我不知道是否真的需要它,但我已经习惯了这样写

编辑:好的,显然我不需要http://,我只是检查了一下。

-

server {
    listen 80;
    server_name  funkyoslo.no;
    root /usr/share/nginx/funkyoslo.webbr.org/html;
    error_page 500 502 503 504 /50x.html;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php$request_uri;
    }
    location ~ '.php$ {
        include fastcgi_params;
        fastcgi_pass http://127.0.0.1:9000;
    }
}