There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

I'm deploying a Laravel app on nginx. Only the main route works, every other throws me a 404

I developed an app in Laravel that uses Google authentication, it works perfectly on my localhost. When I deployed it in my nginx server (ubuntu 24.04) I get the Google login correctly and it proceeds to my main page as expected. But after that, no route is accessible. All of them throw me a 404. I’ve been googling it for ages but I can’t for the life of me find the solution for this.

EDIT: The 404 comes from Laravel, not nginx. The weird part is if I try php artisan route:list on the ser the routes are indeed missing but on the localhost they all show. The code is pretty much the same.

Here’s is my app conf file:


<span style="color:#323232;">server {
</span><span style="color:#323232;">    server_name partituras-cmcgb.duckdns.org;
</span><span style="color:#323232;">    root /var/www/html/partviewer/public;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    index index.php index.html index.htm;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    location / {
</span><span style="color:#323232;">        try_files $uri $uri/ /index.php?$query_string;
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    location ~ .php$ {
</span><span style="color:#323232;">        include snippets/fastcgi-php.conf;
</span><span style="color:#323232;">        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
</span><span style="color:#323232;">        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
</span><span style="color:#323232;">        include fastcgi_params;
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    location ~ /.ht {
</span><span style="color:#323232;">        deny all;
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    error_log /var/log/nginx/partviewer-error.log;
</span><span style="color:#323232;">    access_log /var/log/nginx/partviewer-access.log;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    listen 443 ssl; # managed by Certbot
</span><span style="color:#323232;">    ssl_certificate /etc/letsencrypt/live/partituras-cmcgb.duckdns.org/fullchain.pem; # managed by Certbot
</span><span style="color:#323232;">    ssl_certificate_key /etc/letsencrypt/live/partituras-cmcgb.duckdns.org/privkey.pem; # managed by Certbot
</span><span style="color:#323232;">    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
</span><span style="color:#323232;">    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
</span><span style="color:#323232;">
</span><span style="color:#323232;">}
</span><span style="color:#323232;">server {
</span><span style="color:#323232;">    if ($host = partituras-cmcgb.duckdns.org) {
</span><span style="color:#323232;">        return 301 https://$host$request_uri;
</span><span style="color:#323232;">    } # managed by Certbot
</span><span style="color:#323232;">
</span><span style="color:#323232;">
</span><span style="color:#323232;">    listen 80;
</span><span style="color:#323232;">    server_name partituras-cmcgb.duckdns.org;
</span><span style="color:#323232;">    return 404; # managed by Certbot
</span><span style="color:#323232;">
</span><span style="color:#323232;">
</span><span style="color:#323232;">}
</span>
just_another_person ,

You’re probably going to need logs to rule out any permissions errors or the like.

BaalInvoker ,

I’m not sure, but looks like you’re denying all .htaccess files. Laravel depends on .htaccess to make things work properly

Take a look on Laravel docs - Deployment to make sure your configs are right

spirinolas OP ,

I already went through that. I wouldn’t post here without starting with the official documentation.

BaalInvoker ,

Why are you using that?


<span style="color:#323232;">    location ~ /.ht {
</span><span style="color:#323232;">        deny all;
</span><span style="color:#323232;">    }
</span>

You’re denying the access to your root, which is the public/ folder and has the file .htaccess that has


<span style="color:#323232;"><IfModule mod_rewrite.c>
</span><span style="color:#323232;">    <IfModule mod_negotiation.c>
</span><span style="color:#323232;">        Options -MultiViews -Indexes
</span><span style="color:#323232;">    </IfModule>
</span><span style="color:#323232;">
</span><span style="color:#323232;">    RewriteEngine On
</span><span style="color:#323232;">
</span><span style="color:#323232;">    # Handle Authorization Header
</span><span style="color:#323232;">    RewriteCond %{HTTP:Authorization} .
</span><span style="color:#323232;">    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</span><span style="color:#323232;">
</span><span style="color:#323232;">    # Redirect Trailing Slashes If Not A Folder...
</span><span style="color:#323232;">    RewriteCond %{REQUEST_FILENAME} !-d
</span><span style="color:#323232;">    RewriteCond %{REQUEST_URI} (.+)/$
</span><span style="color:#323232;">    RewriteRule ^ %1 [L,R=301]
</span><span style="color:#323232;">
</span><span style="color:#323232;">    # Send Requests To Front Controller...
</span><span style="color:#323232;">    RewriteCond %{REQUEST_FILENAME} !-d
</span><span style="color:#323232;">    RewriteCond %{REQUEST_FILENAME} !-f
</span><span style="color:#323232;">    RewriteRule ^ index.php [L]
</span><span style="color:#323232;"></IfModule>
</span>

This file handles the income requests and send to the front controller.

fluckx ,

The .htaccess file does nothing on nginx though.

tahoe ,

As far as I know only Apache uses .htaccess files, Nginx works a different way

BaalInvoker ,

Oh, I wasn’t aware of that. I have no experience whatsoever with nginx. I thought that .htaccess was universal

tahoe ,

I was the same until like two months ago when I had to learn Nginx!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines