Nginx和Wordpress永久链接,扩展名为.php

时间:2016-11-23 18:03:16

标签: php wordpress nginx

我的客户的网站使用Wordpress。永久链接设置为/%postname%.php。见.php。因此,网址看起来像http://www.example.com/article-url.php。 我正在使用Nginx和PHP-FPM。永久链接设置不起作用,因为我发现File not found错误。

这是我的Nginx服务器块

server {
        listen 80;
        root /var/www/html/example.com;
        index index.php index.html index.htm;
        error_log /var/log/nginx/example.com.error.log;
        server_name example.com www.example.com;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_read_timeout 300;
        }
        location ~ /\.ht {
                deny all;
        }
}

以下是错误日志FastCGI sent in stderr: "Primary script unknown" while reading re sponse header from upstream ...

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案here ..所以我需要做的是在php位置添加try_files $uri $uri/ /index.php?$args;

我的服务器阻止现在:

server {
        listen 80;
        root /var/www/html/example.com;
        index index.php index.html index.htm;
        error_log /var/log/nginx/example.com.error.log;
        server_name example.com www.example.com;
        location / {
                    try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                    try_files $uri $uri/ /index.php?$args;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
                    fastcgi_read_timeout 300;
        }
        location ~ /\.ht {
                    deny all;
        }
}