404 when using pretty permalinks on new WordPress site on LEMP/nginx

I’ve spent two days trying to problem-solve this, but I’m not a developer/coder and can’t figure out what I’m doing wrong. I want to use pretty permalinks, but will get 404 errors for each page except home.

I used these DigitalOcean guides for Ubuntu 16.04 for my installation. Disabling my theme and all plugins doesn’t solve the problem, nor does using the Nginx Helper plugin.

This is what my config file at /etc/nginx/sites-available/default looks like (comments removed), but I had the same issue with the stock file and just the “try_files $uri $uri/ /index.php?$args;” changed:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        listen 443 ssl http2 default_server;
        listen [::]:443 ssl http2 default_server;

        include snippets/self-signed.conf;
        include snippets/ssl-params.conf;

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

        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 / {
                #try_files $uri $uri/ /index.php;
                try_files $uri $uri/ /index.php?$args;
        location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        location ^~ /\.well-known {
                allow all;

        location ~ /\.ht {
        deny all;

My /var/log/nginx/error.log file is curiously empty.

Any help is appreciated - thanks in advance.

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.

Had to add this piece of code to both the /sites-available/default and /sites-enabled/digitalocean:

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

[…] }

It’s working for me now.

I would recommend starting here. Since WordPress was originally developed to run on Apache with mod_rewrite some custom configuration is required in order to use it with nginx. There are example configuration files there you can compare your current configuration with. Also, be sure to restart nginx when you make configuration changes so they take effect service nginx restart