2016-11-23 42 views
0

我的客戶的網站使用Wordpress。永久鏈接設置爲/%postname%.php。看到有.php。所以一個URL會看起來像http://www.example.com/article-url.php。 我正在使用Nginx和PHP-FPM。那永久鏈接設置不起作用,因爲我得到File not found錯誤。Nginx和WordPress的永久鏈接.php擴展名爲

這裏是我的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 ...

如何糾正呢?

回答

0

我已經找到了解決辦法here ..所以我需要做的就是添加try_files $uri $uri/ /index.php?$args;下的PHP位置

我的服務器塊現在:

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; 
     } 
}