Post 带有Nginx参数的Laravel为空
我刚刚安装了Nginx,我正试图用它来托管一个Laravel应用程序,但我遇到了两个问题Post 带有Nginx参数的Laravel为空,post,parameters,nginx,laravel,Post,Parameters,Nginx,Laravel,我刚刚安装了Nginx,我正试图用它来托管一个Laravel应用程序,但我遇到了两个问题 对于GET方法,我总是在输入中获得一个额外的参数。 使用PostMan(Chrome)进行测试,我设置了目标URL和所需的参数,然后发送请求。我得到的输出总是包含它不应该包含的REQUEST\u URI。示例输出: 我的参数(以上)将不显示为DELETE或PUT,而对于POST,我将只获得请求URI Nginx vhost(后面) 快速CGI_参数: fastcgi_param QUERY_STR
- 使用PostMan(Chrome)进行测试,我设置了目标URL和所需的参数,然后发送请求。我得到的输出总是包含它不应该包含的
。示例输出:REQUEST\u URI
请求URI
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
#fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
nginx.conf只更改了一件事,即keepalive\u timeout
从65更改为15
所以我完全不知道这一切哪里出了问题。但我必须提到的是,在我拥有的另外两个环境中(一个使用Lighttpd,另一个使用Apache2),该应用程序工作得非常完美
根据我所注意到的,其全部简化为以下代码:
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
这将使工作。。。并添加附加参数最好避免在nginx配置中进行不必要的重写(请参阅),尤其是负责将请求传递给Laravel前端控制器的参数: 您对Laravel的所有需求是:
location / {
index index.php index.html index.htm;
try_files $uri $uri/ index.php?$query_string;
}
首先尝试直接访问文件,然后是目录,如果两者都不存在,则将请求传递到index.php$query\u字符串
传递很重要,因为它将包含丢失的$\u GET
数据
下面是我自己的FastCGI配置:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
至于意外输入,这可能是您当前重写的工作方式,但可以肯定的是,您将输出什么?从您的配置:
rewrite ^/(.*)$ /index.php?/$1 last;
这里有一个重定向到/index.php?/$1
(例如/index.php?/some/path
)
在这里,您通过^(.+\.php)(/.+$
regex(例如/index.php/some/path
)来划分路径
你注意到区别了吗?这对我很有用:
location / {
index index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
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;
}
这是一种适用于我的NGINX和Laravel配置
server {
listen 80;
server_name sub.domain.com;
set $root_path '/var/www/html/application_name/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
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;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
我遇到了类似的问题,我用以下配置修复了它:
server {
listen 80;
server_name subdomain.domain.com;
root /var/www/dir/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;
try_files $uri $uri/ /index.php?&$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
#deny all;
}
}
dd(输入::all())代码>这是我要输出的内容。。。不,不是Input::all()
设置了不需要的参数right。尝试建议的配置并告诉我是否可以。只是尝试了一下,通过注释包含重写规则的if
s,现在我没有得到任何参数输出。谢谢您的帮助,但是您的配置对我没有帮助。您是否替换了您描述为“其全部简化为以下代码”的部分用我建议的代码?我只是不确定这是否清楚,我实际上删除了fastcgi\u spli
部分,现在我得到了参数,但我仍然有[/api/user]=>//这不应该出现在这里
问题,我只是添加了一点,但您已经这样配置了nginx。最后,您的重写^/(.*)$/index.php?/$1代码>负责将路径添加到参数。请原谅我的无知,否则我该怎么做?这就是我在谷歌上看到的所有结果(搜索laravel nginx
)所暗示的。你应该按照你想要的方式去做。Nginx有一种非常灵活的配置语言,允许配置任何所需的行为。我建议您阅读文档并从头开始编写配置。有用的链接:我不认为Laravel需要一个q
参数,我以前从未见过它。但是在CIYes中看到了它,我在没有q
的情况下对它进行了测试,结果很好。所以try_文件$uri$uri//index.php?$args代码>有效。唯一对我有效的关键点是index.php?&$args代码>,在debian 9.6上运行Laravel 4.2和php7.0
location / {
index index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
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;
}
server {
listen 80;
server_name sub.domain.com;
set $root_path '/var/www/html/application_name/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
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;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
server_name subdomain.domain.com;
root /var/www/dir/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;
try_files $uri $uri/ /index.php?&$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
#deny all;
}
}