1

My client's website use Wordpress. The permalink is set to /%postname%.php. See there is .php. So an URL would be look like http://www.example.com/article-url.php. I am using Nginx and PHP-FPM. That permalink setting did not work as I got File not found error.

Here is my Nginx server block

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

Here is the error log says FastCGI sent in stderr: "Primary script unknown" while reading re sponse header from upstream ...

How to correct this?

1 Answer 1

1

I've found the solution here.. So what I need to do is to add try_files $uri $uri/ /index.php?$args; under php location

My server block now:

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;
        }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.