简体   繁体   中英

500 error with Nginx and WordPress pretty permalinks

Ran into a 500 issue when running Nginx and WP together and setting pretty permalinks. I've been trying a bunch of different methods from Google but none seems to help.

Config -

server {
        listen   80;

        root /var/www/mydomain.com/public_html;
        index index.php index.html index.htm;

        server_name .mydomain.com;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

        }
}

All files load perfectly well, and the pages work if using the default permalinks setting. Strange thing is, if I check the network log I first see a 200 OK being received, then immediately followed by a 500. Any ideas?

Edit: Setting to close as I'm switching to Apache instead. Will mark correct answer as it seems to have helped others.

try:

try_files $uri $uri/ /index.php?q=$uri&$args;

AND:

fastcgi_index /index.php;

(note the / )

Also above answer by Rufinus is correct.

Here is correct . You Forget to define Index . So nginx don't know which file to lockup and process. Hope this help u out.

location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}

Your Config does not have fastcgi_parm .

add this line to your config. Its main part of Nginx Config.

change /home/public_html with your website path location

fastcgi_param SCRIPT_FILENAME /home/public_html$fastcgi_script_name;

Here is my Whole wordpress config file. I Hope that works. Its working Nginx config file with pretty urls.

server {
                listen 80;
                server_name example.com;
                root /home/public_html;
                index index.php index.htm index.html;

location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location /favicon.ico { access_log off; log_not_found off; }
location ~* \.(jpg|jpeg|gif|png|js|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           360d;
}


location ~ /\. {
    access_log off;
    log_not_found off; 
    deny all;
}


location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/public_html$fastcgi_script_name;
include fastcgi_params;
}
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM