Laravel 5 - 使用URL查询字符串的NGINX服务器配置问题

Mat*_*itt 2 routing nginx query-string laravel-5

Laravel没有从URL查询字符串中接收任何$ _GET变量.$ _GET和Input :: all()为空.

例:

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

"country = US"从未出现在我的$ _GET变量中

经过大量研究并尝试了许多不同的NGINX配置,我现在只能在使用此示例时生成结果.

例:

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

$ _GET变量现在显示国家/地区名称值对.

允许URL中的查询字符串的正确配置是什么?

我的"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;
}
Run Code Online (Sandbox Code Playgroud)

}

小智 5

除了被注释外,这似乎是正确的.

location / {
    #try_files $uri $uri/ /index.php?$query_string;
}
Run Code Online (Sandbox Code Playgroud)

我在测试中使用的裸骨是:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

$ query_string和$ args在功能上完全相同: NGINX Docs


Mat*_*itt 5

这是最终为我工作的启用站点的 NGINX 服务器配置...

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;
    }
}
Run Code Online (Sandbox Code Playgroud)