Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

warpig's avatar
Level 12

404 Not Found on "/". Nginx config

Can someone review my config file? When trying to access the site on localhost I'm getting a 404 message.

"404 Not Found nginx/1.18.0 (Ubuntu)"

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

        root /var/www/sickofmetal/public/;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-Frame-Options "nosniff";

        index index.php;

        server_name _;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }

        error_page 404 /index.php;

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        }

        location ~ /\.(?!well-known).* {
                deny all;
        }
}

what could be wrong? the folder as far as i'm concerned look good to me

nginx logs: 2024/02/27 11:06:59 [notice] 15337#15337: signal process started

0 likes
2 replies
Tray2's avatar

Try this link

https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/#step-configure-nginx-virtual-host-for-laravel

server {
         listen 80;
         listen [::]:80 ipv6only=on;
 
         # Log files for Debugging
         access_log /var/log/nginx/laravel-access.log;
         error_log /var/log/nginx/laravel-error.log;
 
         # Webroot Directory for Laravel project
         root /var/www/laravel/public;
         index index.php index.html index.htm;
 
         # Your Domain Name
         server_name laravel.hakase-labs.co;
 
         location / {
                 try_files $uri $uri/ /index.php?$query_string;
         }
 
         # PHP-FPM Configuration Nginx
         location ~ \.php$ {
                 try_files $uri =404;
                 fastcgi_split_path_info ^(.+\.php)(/.+)$;
                 fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include fastcgi_params;
         }
 }

Please or to participate in this conversation.