当jwilder/nginx-proxy大于8kb/16KB(和2MB)的文件时,Laravel POST TokenMismatchException [英] Laravel POST TokenMismatchException for files bigger than 8kb/16KB (and 2MB) when jwilder/nginx-proxy

查看:136
本文介绍了当jwilder/nginx-proxy大于8kb/16KB(和2MB)的文件时,Laravel POST TokenMismatchException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel 5.4中编写应用程序,并对其进行了泊坞处理.要在托管中使用子域,请使用jwilder/nginx-proxy反向代理将请求重定向到我的容器.在我的应用程序中,允许用户上传文件,但是,当我在主机上运行该文件并发送POST"multipart/form-data"请求,要求文件大于8kb时,laravel返回TokenMismatchException.这是我的配置:

I write application in Laravel 5.4 and dockerized it. To use subdomain in my hosting I use jwilder/nginx-proxy reverse proxy to redirect requests to my container. In my application allow user to upload files but, when I run it on my hosting and send POST "multipart/form-data" request for files larger than 8kb, then laravel return TokenMismatchException. Here is my configuration:

在我使用的Dockerfile

FROM php:7.1.5-alpine
...
ADD ./uploads.php.ini /usr/local/etc/php/conf.d/uploads.ini
...
CMD ... && php artisan serve --host=0.0.0.0 --port=80

uploads.php.ini中,我有:

file_uploads = On
memory_limit = 100M
upload_max_filesize = 200M
post_max_size =500M
max_execution_time = 600

我以这种方式运行jwilder/nginx-proxy:

I run jwilder/nginx-proxy in this way:

docker pull jwilder/nginx-proxy:alpin
docker run -d -p 80:80 -p 443:443 -v /path/on/host/to/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy:alpine

my_proxy.conf中(对于nginx配置),我有;

In my_proxy.conf (for nginx configuration) I have;

server_tokens off;
client_max_body_size 0;

:(

推荐答案

我花了很多时间来测试不同的方法,最终我找到了两个解决方案.文件my_proxy.conf应该看起来像这样:

I took many hours to test different approach and finnaly i found two solutions. The file my_proxy.conf should looks like this:

server_tokens off;
client_max_body_size 0;
proxy_request_buffering off;

或类似这样(例如,文件< = 10MB)

Or like this (for file <=10MB as example)

server_tokens off;
client_max_body_size 0;
client_body_buffer_size 10M; 

server_tokens on/off不是问题解决方案的一部分.

The server_tokens on/off is not part of problem solution.

可能的问题是因为nginx将大"请求划分为较小的请求,然后分别代理"(因此laravel仅授权大"请求的第一"部分/部分,而不授权其他部分).

Probably problem is because nginx divide 'big' request to smaller one and 'proxy' them separately (so laravel authorize only 'first' segment/part of 'big' request and not authorize other parts).

当然,首先提出的解决方案更好,因为我们不需要设置任何限制.但是,如果有人想为代理设置限制(例如20MB),则应更改client_max_body_size 20M;.

Of course first proposed solution is better because we not need to set any limit. But if someone want's to set limit into proxy (e.g. 20MB), then should change client_max_body_size 20M;.

这篇关于当jwilder/nginx-proxy大于8kb/16KB(和2MB)的文件时,Laravel POST TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆