4

Laravel is not receiving any $_GET variables from the URL query string. The $_GET and Input::all() are empty.

Example:

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

The "country=US" never shows up in my $_GET variable

After much research and trying many different NGINX configurations, I can now only produce results when this example is used.

Example:

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

The $_GET variable now shows the country name value pair.

What is the proper configuration to allow query strings within the URL?

My current sites-enabled configuration for my "example.app" is...

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

}

4 Answers 4

6

This appears correct, aside from being commented out.

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

The bare bones one I use in testing is:

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 Docs

Sign up to request clarification or add additional context in comments.

1 Comment

my try_files was: try_files $uri $uri/ =404; ...... I just needed to replace the =404 with /index.php?$args; to tell nginx to treat these urls as query strings and not "give up" and display a 404 page because the files don't actually exist .... This was to get CPVLabs working on Ubuntu 14.04 (Digital Ocean Droplet). THANK YOU FOR AN INSTANT SOLUTION ... I <3 STACK OVERFLOW!!!!
6

This is the sites-enabled NGINX server configuration 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;
    }
}

2 Comments

You may want to just confirm that this is the actual answer to the problem. I'm experiencing the same issue. When I add "error_page 404 /index.php" to the config, it seems to work, but actually all the responses are 404 instead of the expected 200, and POST requests no longer work.
This solved a very irritating 404 issue for me thank you :)
1

For me it worked only by changing try_files $uri $uri/ /index.php?$query_string; to try_files $uri $uri/ /index.php?$args inside location / block on ubuntu (14.04) nginx

Comments

0

My NGINX congfiguration was something like this:-

From

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

To

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

I just remove the is_args from try_files and working fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.