Skip to content

Nginx: All Pages Return 404 Not Found except Home Page

I’m using Magento 2.4.4, I’ve set up the existing project, but all page goes to 404 except the homepage. I’m using Nginx for the first time so still figuring out how to configure it.

/etc/nginx/sites-available/ruralking.local:

server {
    listen 80;
    server_name ruralking.local www.ruralking.local;
    root /var/www/ruralking.local/pub;

    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_buffers 16 256k;
        fastcgi_buffer_size 256k;
    }

    location ~ /.ht {
        deny all;
    }
}