Why do I get a 404 error after deploying a Laravel API?

Hello everyone
I have some issue to reach my Laravel API hosted on Render. Everything works fine in localhost but when I try with the Render url, I get an error 404. I used this tutorial to deploy my api and I’m using postman to make the requests.
The only thing I have in the log is :

::1 - - [26/Sep/2024:21:07:46 +0000] “GET /api HTTP/1.1” 404 485 “-” “PostmanRuntime/7.42.0”

I found some topics about it on the forum but everytimes, the topics was closed without giving a solution…

I’m using laravel 11 with php 8.3.

Does someone know how to fix this ?
Thanks

So I did some digging. Apparently the issue is when I’m adding something behind the Render url… This “https://my_url/” works but this “https://my_url/api” does not.

So I told my self “maybe the routes are not created” so I added this commad “php artisan route:list” and here is the output :

POST api/products … products.store › ProductController@store

GET|HEAD api/products … products.index › ProductController@index

GET|HEAD api … generated::lnwA0mh8RHztYh4y

As you can see, the routes are created. So I think the the issue is comming from the “nginx-site.conf” file :

server {
  # Render provisions and terminates SSL
  listen 80;

  # Make site accessible from http://localhost/
  server_name _;

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

  # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
  sendfile off;

  # Add stdout logging
  error_log /dev/stdout info;
  access_log /dev/stdout;

  # block access to sensitive information about git
  location /.git {
    deny all;
    return 403;
  }

  add_header X-Frame-Options "SAMEORIGIN";
  add_header X-XSS-Protection "1; mode=block";
  add_header X-Content-Type-Options "nosniff";

  charset utf-8;

  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 ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
    expires 5d;
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    include fastcgi_params+
  }

  # deny access to . files
  location ~ /\. {
    log_not_found off;
    deny all;+
  }

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

But I don’t know where… Does someone sees what is wrong ?

Hi there,

It is hard to answer this question without being able to look at the specific service having the issue. What you have provided looks okay to me. Please use the “Contact Support” link from our dashboard to open a ticket directly with us?

Regards,

Keith
Render Support, UTC+10 :australia: