Laravel 5 - NGINX server configuration issue with url strings

Laravel does not get $ _GET variables from the URL query string. $ _GET and Input :: all () are empty.

Example:

example.app/ex/login.php?country=US

"Country = USA" never appears in my $ _GET variable

After much research and testing of many different NGINX configurations, I can now only get results using this example.

Example:

example.app/index.php/ex/login.php?country=US

The $ _GET variable now shows a pair of country name values.

What is the correct configuration to include query strings in the URL?

My current node-enabled config for my "example.app" ...

server {
listen 80;
server_name example.app;
root /home/vagrant/Code/public;

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; }

access_log off;
error_log  /var/log/nginx/registration.app-error.log error;

error_page 404 /index.php;

sendfile off;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
}

location ~ /\.ht {
    deny all;
}

      

}

+2


source to share


3 answers


This is a site-enabled NGINX server config that ended up working for me ...



server {
    listen 80;
    server_name registration.app;
    root /home/vagrant/Code/registration/public;

    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/registration.app-error.log error;
    error_page 404 /index.php;
    sendfile off;

    # Point index to the Laravel front controller.
    index index.php;

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

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

    location ~ /\.ht {
        #deny all;
    }
}

      

+3


source


This seems to be correct, aside from the comment.

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

      

Bare bones I use when testing:



server {
    listen 80 default_server;

    root /var/www/project/public;
    index index.php
    server_name localhost;
    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
    }
}

      

$ query_string and $ args are functionally identical according to: NGINX Documentation

+5


source


For me this only worked by changing            try_files $uri $uri/ /index.php?$query_string;

to try_files $uri $uri/ /index.php?$args

inside a block location /

on ubuntu (14.04) nginx

0


source







All Articles