【问题标题】:Nginx and Wordpress permalink with .php extension带有 .php 扩展名的 Nginx 和 Wordpress 永久链接
【发布时间】:2016-11-23 18:03:16
【问题描述】:

我客户的网站使用 Wordpress。永久链接设置为/%postname%.php。看到有.php。所以 URL 看起来像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 ...

如何解决这个问题?

【问题讨论】:

    标签: php wordpress nginx


    【解决方案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;
            }
    }
    

    【讨论】:

    • 谢谢,真的很有帮助!! :)
    猜你喜欢
    • 2017-07-27
    • 2011-01-10
    • 2013-03-26
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多