Question

WordPress Pretty Permalinks with Nginx/Ubuntu, WordPress in Subfolder (no Apache)

Hi,

I’ve been struggling for over a day now to get pretty permalinks to work on WordPress. I’ve tried quite a few solutions from around the web and nothing has been working. This is my conf file:

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

        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;

        server_name website.com www.website.com;

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

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

        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
            expires max;
            log_not_found off;
        }

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            fastcgi_pass   unix:/run/php/php7.2-fpm.sock;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO $fastcgi_path_info;
            fastcgi_index  index.php;
            include        fastcgi_params;
        }

        location /blog {
           root /var/www/html/blog;
           index index.php index.html index.htm index.nginx-debian.html;
           try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ /blog/.+\.php$ {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                fastcgi_pass   unix:/run/php/php7.2-fpm.sock;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO $fastcgi_path_info;
                fastcgi_index  index.php;
                include        fastcgi_params;
        }

        location ~ /\.ht {
                deny all;
        }
}

Can anyone tell me what I’m doing incorrectly, please? I did not install this with a one-click-install (otherwise it would be using Apache). Wordpress is installed under /blog. Everything works fine except I am unable to publish posts when pretty permalinks are enabled. Thank you!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
July 26, 2019
Accepted Answer

Hello,

What you’ve got there looks correct, you just need to change one slight thing:

        location /blog {
           root /var/www/html/blog;
           index index.php index.html index.htm index.nginx-debian.html;
           try_files $uri $uri/ /blog/index.php$is_args$args;
        }

Note the blog part before the /index.php, then do a config test and restart.

Let me know how it goes! Bobby

It works now, thank you very much!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel