skip to Main Content

I have a laravel project with Livewire Library installed, i have problems with query string parameter when i change from Apache to Nginx, the path is change to empty, in example the main path is http://example.com/active , when i use livewire for pagination it should http://example.com/active?page=1, but when i change the pagination to page 2 it change to http://example.com/?page=2 seems without path name, and when return to pagination page 1 the path is empty http://example.com/ but the page is still working.

I have No issue when using apache with standard config for laravel, but when i change to my production server and based to Nginx the path issues come up, but only in page that i’m using livewire library in page or for pagination, maybe people here have a same experience and problems, thanks in advance for any help.

Here my nginx config :

server {
   listen 80;
   server_name _;

   root /var/www/project/public;

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

   }

   location ~ .php$ {
       fastcgi_split_path_info ^(.+.php)(/.+)$;
       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME       $realpath_root$fastcgi_script_name;
   }   
}    

2

Answers


  1. This is the config I use all the time (for development using Docker Compose) and it works, try mine and see if it works, then start deleting stuff until it stops working again:

    server {
        listen 80;
    
        index index.php;
    
        error_log  /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;
    
        root /var/www/public;
    
        location ~ .php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
            gzip_static on;
        }
    }
    

    I think it might be the missing include fastcgi_params; or fastcgi_param PATH_INFO $fastcgi_path_info;.

    Login or Signup to reply.
  2. Add this to your nginx config file

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf|woff2|woff|ttf|mp3|mp4|ogg|json|svg|css|js)$       
    {       
       try_files $uri $uri/ /index.php?$query_string;
    }
    

    This worked for me after a long period of trying.

    You can remove the extensions you don`t need.

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