What can I do to fix error 404 page on nginx on Ubuntu 18.04?

March 16, 2019 343 views
Nginx WordPress Ubuntu 18.04

I am attempting to switch from apache2 to nginx on Ubuntu 18.04 from the wordpress one click install. I have installed nginx and php-fpm. I did what I thought was a full conversion into nginx using the config files and then uninstalled apache2 but it seems I am missing something... this is my /etc/nginx/sites_available/default.conf, i'm not sure what else is immediately useful so if there is other info needed I can scrounge that up.

server {

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

        server_name cameingle.com www.cameingle.com;

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

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

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

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/cameingle.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/cameingle.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.cameingle.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = cameingle.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        server_name cameingle.com www.cameingle.com;
    return 404; # managed by Certbot




}
1 Answer

Greetings!

This can be difficult to eyeball so I'm going to try my best. I think it's this line:

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

I believe adding the $uri to the end may be breaking it. What if it were instead:

try_files $uri $uri/ /index.php?$args;

You can find more about Nginx config for Wordpress here:

https://codex.wordpress.org/Nginx

Jarland

Have another answer? Share your knowledge.