简体   繁体   中英

Nginx with wordpress 404 on all pages

Although this issue has been answered many times but still its not working for me. I am getting 404 on all pages except home page on Nginx.

I am posting in my configuration below:

server {
        listen 80 ;
        listen [::]:80;

        root /var/www/html/p/swear;
        index index.php index.html index.htm;

        server_name skinnybikiniswimwear.org;

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


            location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                try_files $uri /index.php?args =404;
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

I am not able to find the issue in this configuration.

Wordpress is installed at: /var/www/html/p/swear

Thanks

Try this :

    location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$is_args$args =404;
    }


    if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
    }

Having had a lot of failures configuring wordpress to work with nginx, the rewrite rule solves every issue with the 404 errors.

try removing slash in front of /$uri/

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

location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass php;
}

Images does not because you dont have nothing in your server block about images. You have to add the images into your server block.

For example:

location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mp3)$ {
        root /home/example/public_html
    }

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