WordPress 404 in nginx logs after changing permalinks

So I have my landing page setup in /usr/share/nginx/html and blog in /usr/share/nginx/blog

As you can see in the config below, the blog is configured as an alias. Whenever someone tries to reach the blog eg: you.com/blog it takes them to you.com/blog/. Still not a big deal to worry about. So in wordpress, the urls are setup to plain. Everything works till this point without any issues. Now, due to asthetics, the urls need to look better, ie: post-name. Eg: you.com/blog/name-of-my-post. If the config is changed in wordpress from plain to post-name nginx gives a 404 with the following message

2017/05/03 09:28:00 [error] 2869#0: *1492652 "/usr/share/nginx/blog/my-post/index.html" is not found (2: No such file or directory), client:, server: you.com, request: "GET /blog/my-post/ HTTP/1.1", host: "you.com", referrer: "https://you.com/blog/"

I’m noticing index.html is getting attached at the end. After trying out different changes in the php/blog block I’m still stuck on 404. Here’s the config we’re running.

server {
    root /usr/share/nginx/html;
    listen 443 ssl;
    ssl_protocols TLSv1.1 TLSv1.2 ;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_certificate /var/keys/api_ssl.crt;
    ssl_certificate_key /var/keys/api_priv.key;
    server_name you.com;

    index index.html index.php index.htm;

    location / {
    try_files $uri $uri.html $uri/ uri.html = 404;

    location /blog {
        alias /usr/share/nginx/blog;
        if (!-e $request_filename) {
           rewrite /blog/wp-admin$ $scheme://$host$uri/ permanent;
           rewrite ^(/[^/]+)?(/wp-.*) $2 last;
           rewrite ^(/[^/]+)?(/.*.php) $2 last;
        try_files $uri $uri/ /index.php?$args;
        location ~ .php {
            include fastcgi_params;
            fastcgi_index index.php;

How can I get the /blog/my-post-here instead of the plain type you.com/blog/?p=10

Read more here: WordPress 404 in nginx logs after changing permalinks

Leave a Reply

Your email address will not be published. Required fields are marked *