this post was submitted on 10 Sep 2024
8 points (78.6% liked)

Selfhosted

39964 readers
254 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS
 

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:

server {
    server_name partituras-cmcgb.duckdns.org;
    root /var/www/html/partviewer/public;

    index index.php index.html index.htm;

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

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

    location ~ /\.ht {
        deny all;
    }

    error_log /var/log/nginx/partviewer-error.log;
    access_log /var/log/nginx/partviewer-access.log;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/partituras-cmcgb.duckdns.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/partituras-cmcgb.duckdns.org/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 = partituras-cmcgb.duckdns.org) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name partituras-cmcgb.duckdns.org;
    return 404; # managed by Certbot


}
all 16 comments
sorted by: hot top controversial new old
[–] [email protected] 4 points 1 month ago

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

[–] [email protected] 2 points 1 month ago* (last edited 1 month ago)

Check out this page. https://laravel.com/docs/10.x/deployment

You have to redirect all requests to index.php in the public folder. There is a sample Nginx configuration file on this page.

[–] [email protected] 2 points 1 month ago (1 children)

Does the uid you are using to run nginx have permissions to read the root folder (defined above as /var/www/html/partviewer/public , not the actual linux root) and below?

[–] [email protected] 1 points 1 month ago

Yeah, sounds like a permissions error.

[–] [email protected] 1 points 1 month ago (1 children)

could you replace try_files $uri $uri/ /index.php?$query_string; with try_files $uri $uri/ /index.php?$is_args$args

That might work

[–] [email protected] 1 points 1 month ago (1 children)

It was the first "solution" on google. Didn't work.

[–] [email protected] 1 points 1 month ago (1 children)

Oh, does the route hit your location? What's in the logs?

[–] [email protected] 1 points 1 month ago* (last edited 1 month ago)

The correct URL appears in the browser but the page shows a 404. According to the logs they don't exist...but they're there...

[–] [email protected] 1 points 1 month ago

Could it be a route cache thing? may be worth trying artisan route:clear followed by artisan route:cache

[–] [email protected] 1 points 1 month ago (2 children)

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

[–] [email protected] 9 points 1 month ago (1 children)

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

[–] [email protected] 1 points 1 month ago (1 children)

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

[–] [email protected] -1 points 1 month ago (1 children)

Why are you using that?

    location ~ /\.ht {
        deny all;
    }

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

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

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

[–] [email protected] 2 points 1 month ago

The .htaccess file does nothing on nginx though.