skip to Main Content

I have a Laravel project. It works on Mac os with nginx.
I recentlly installed a CentOs 8. I installed Nginx on it and add the configuration bellow:


server {
    listen 8001;
    server_name _;
    root /usr/share/nginx/html/reservation_laravel/public;

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

    index index.html index.htm index.php;

    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 ~ .php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

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


All routes inside web.php work fine but API routes not working!
Same configuration is working on an Ubuntu server!

2

Answers


  1. When you write on api.php add api on your url like

    '/get-list'
    

    then you call it

     /api/get-list
    
    
    Login or Signup to reply.
  2. I’m not sure whether you have a rewrite issue. Take a look at Laravel’s installation documentation. There’s a section about rewrite configuration that might give you some insight:

    https://laravel.com/docs/6.x/installation#pretty-urls

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search