Laravel Nginx 查询字符串参数
Laravel Nginx Query String Parameters
我正在使用 Laravel 5.2 和 Nginx,并且在我的开发服务器上运行良好。
例如:
http://example.com/results?page=2
开发服务器
LengthAwarePaginator::resolveCurrentPage(); // returns 2
Paginator::resolveCurrentPage(); // returns 2
$request->input('page'); // returns 2
但在生产服务器中
LengthAwarePaginator::resolveCurrentPage(); // returns 1
Paginator::resolveCurrentPage(); // returns 1
$request->input('page'); // returns null
生产服务器配置
server {
listen 80 ;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/laravel/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php;
}
location @rewrite {
rewrite ^(.*)$ /index.php?_url=;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
}
}
开发服务器配置
server {
listen 80;
server_name example.com;
client_max_body_size 50M;
root /var/www/html/laravel/public;
index index.html index.htm index.php;
try_files $uri $uri/ @rewrite;
add_header 'Access-Control-Allow-Origin' '*';
location @rewrite {
rewrite ^(.*)$ /index.php?_url=;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "upload_max_filesize=52428800 \n post_max_size=53477376 \n memory_limit=536870912";
fastcgi_param APPLICATION_ENV development;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我应该对服务器 nginx 配置进行哪些更改?
任何帮助表示赞赏!
已解决!
我需要做一些更正,因为 location ~ \.php$ {}
中有两个 fastcgi_pass
,所以不得不更改
location ~ \.php$ {
try_files $uri $uri/ /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
}
到
location ~ \.php$ {
try_files $uri $uri/ /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
}
并在 location / {}
中修改 try_files
因此必须更改
location / {
try_files $uri $uri/ /index.php;
}
到
location / {
try_files $uri $uri/ /index.php?$query_string;
}
我正在使用 Laravel 5.2 和 Nginx,并且在我的开发服务器上运行良好。
例如:
http://example.com/results?page=2
开发服务器
LengthAwarePaginator::resolveCurrentPage(); // returns 2
Paginator::resolveCurrentPage(); // returns 2
$request->input('page'); // returns 2
但在生产服务器中
LengthAwarePaginator::resolveCurrentPage(); // returns 1
Paginator::resolveCurrentPage(); // returns 1
$request->input('page'); // returns null
生产服务器配置
server {
listen 80 ;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/laravel/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php;
}
location @rewrite {
rewrite ^(.*)$ /index.php?_url=;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
}
}
开发服务器配置
server {
listen 80;
server_name example.com;
client_max_body_size 50M;
root /var/www/html/laravel/public;
index index.html index.htm index.php;
try_files $uri $uri/ @rewrite;
add_header 'Access-Control-Allow-Origin' '*';
location @rewrite {
rewrite ^(.*)$ /index.php?_url=;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "upload_max_filesize=52428800 \n post_max_size=53477376 \n memory_limit=536870912";
fastcgi_param APPLICATION_ENV development;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我应该对服务器 nginx 配置进行哪些更改? 任何帮助表示赞赏!
已解决!
我需要做一些更正,因为 location ~ \.php$ {}
中有两个 fastcgi_pass
,所以不得不更改
location ~ \.php$ { try_files $uri $uri/ /index.php$is_args$args; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/var/run/php5-fpm.sock; include /etc/nginx/fastcgi_params; }
到
location ~ \.php$ { try_files $uri $uri/ /index.php$is_args$args; fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/var/run/php5-fpm.sock; include /etc/nginx/fastcgi_params; }
并在 location / {}
中修改 try_files
因此必须更改
location / { try_files $uri $uri/ /index.php; }
到
location / { try_files $uri $uri/ /index.php?$query_string; }