File 无法使用Nginx(反向代理&x2B;SSL协商)和Tomcat上载大文件
配置:File 无法使用Nginx(反向代理&x2B;SSL协商)和Tomcat上载大文件,file,tomcat,upload,nginx,reverse-proxy,File,Tomcat,Upload,Nginx,Reverse Proxy,配置: Nginx作为反向代理+SSL协商 阿帕奇猫 除了文件上传,一切似乎都很好。由于某些原因,文件上载从未完成。通过下面列出的配置,我可以上传小文件(4K)。上载194K文件失败。当我将“client\u body\u buffer\u size”增加到256K时,我可以上载194K文件,但500K文件上载失败。将“客户端\正文\缓冲区\大小”增加到256K以上不会产生任何影响 注意:当我直接访问Tomcat并上传500K文件时,它会在几毫秒内完成。 看来Nginx配置有问题。如有任何建
- Nginx作为反向代理+SSL协商
- 阿帕奇猫李>
upstream tomcat_server {
server 127.0.0.1:9090 fail_timeout=0;
keepalive 16;
}
location / {
root /xyz;
proxy_http_version 1.1;
proxy_pass http://tomcat_server;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering on;
proxy_connect_timeout 75;
proxy_send_timeout 180;
proxy_read_timeout 1200;
keepalive_timeout 120;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_path /tmp/nginx/proxy;
proxy_temp_file_write_size 1000m;
}
我曾尝试向nginx config添加几个其他参数(客户端\正文\临时\路径、代理\临时\路径、代理\临时\文件\写入\大小)。他们似乎没有帮助
====
更新-2013/07/30:
进一步调查显示,我们上传196K及以上文件时遇到问题。194K文件工作。“客户端\正文\缓冲区\大小”值设置为256K
Nginx调试日志在出现故障时显示以下内容:
2013/07/30 16:29:57 [debug] 14208#0: *1 recv: fd:11 2606 of 16384
2013/07/30 16:29:57 [debug] 14208#0: *1 http proxy status 200 "200 OK"
2013/07/30 16:29:57 [debug] 14208#0: *1 http proxy header: "Server: Apache-Coyote/1.1"
2013/07/30 16:29:57 [debug] 14208#0: *1 http proxy header: "Content-Type: text/html;charset=utf-8"
2013/07/30 16:29:57 [debug] 14208#0: *1 http proxy header: "Date: Tue, 30 Jul 2013 22:29:57 GMT"
2013/07/30 16:29:57 [debug] 14208#0: *1 http proxy header: "Connection: close"
2013/07/30 16:29:57 [debug] 14208#0: *1 http proxy header done
2013/07/30 16:29:57 [debug] 14208#0: *1 xslt filter header
2013/07/30 16:29:57 [debug] 14208#0: *1 HTTP/1.1 200 OK^M
Server: nginx/1.5.2^M
Date: Tue, 30 Jul 2013 22:29:57 GMT^M
Content-Type: text/html;charset=utf-8^M
Transfer-Encoding: chunked^M
Connection: keep-alive^M
2013/07/30 16:29:57 [debug] 14208#0: *1 write new buf t:1 f:0 000000001E61DAD8, pos 000000001E61DAD8, size: 168 file: 0, size: 0
2013/07/30 16:29:57 [debug] 14208#0: *1 http write filter: l:0 f:0 s:168
2013/07/30 16:29:57 [debug] 14208#0: *1 http cacheable: 0
2013/07/30 16:29:57 [debug] 14208#0: *1 posix_memalign: 000000001E62D450:4096 @16
2013/07/30 16:29:57 [debug] 14208#0: *1 http proxy filter init s:200 h:0 c:0 l:-1
2013/07/30 16:29:57 [debug] 14208#0: *1 http upstream process upstream
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe read upstream: 1
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe preread: 2465
2013/07/30 16:29:57 [debug] 14208#0: *1 readv: 1:13778
2013/07/30 16:29:57 [debug] 14208#0: *1 readv() not ready (11: Resource temporarily unavailable)
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe recv chain: -2
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe buf free s:0 t:1 f:0 000000001E61DBD0, pos 000000001E61DC5D, size: 2465 file: 0, size: 0
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe length: -1
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe write downstream: 1
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe write busy: 0
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe write: out:0000000000000000, f:0
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe read upstream: 0
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe buf free s:0 t:1 f:0 000000001E61DBD0, pos 000000001E61DC5D, size: 2465 file: 0, size: 0
2013/07/30 16:29:57 [debug] 14208#0: *1 pipe length: -1
2013/07/30 16:29:57 [debug] 14208#0: *1 event timer add: 11: 180000:1375223577332
2013/07/30 16:29:57 [debug] 14208#0: *1 http upstream request: "/upload/html?"
2013/07/30 16:29:57 [debug] 14208#0: *1 http upstream send request handler
2013/07/30 16:29:57 [debug] 14208#0: timer delta: 6
2013/07/30 16:29:57 [debug] 14208#0: posted events 0000000000000000
2013/07/30 16:29:57 [debug] 14208#0: worker cycle
2013/07/30 16:29:57 [debug] 14208#0: epoll timer: 179994
我注意到上面的日志片段中有“http上游发送请求处理程序”,其中与成功案例一样,我看到以下内容:
2013/07/30 16:29:44 [debug] 14208#0: *1 http upstream dummy handler
知道“http上游发送请求处理程序”和“http上游虚拟处理程序”的含义以及它们的含义吗?您要查找的设置可能是 语法:客户端\最大\正文\大小
默认值:客户机最大机身尺寸1m
上下文:http、服务器、位置 设置“内容长度”请求标头字段中指定的客户端请求正文的最大允许大小。如果请求中的大小超过配置的值,则413(请求实体太大)错误将返回给客户端。请注意,浏览器无法正确显示此错误。将大小设置为0将禁用对客户端请求正文大小的检查
我也有同样的问题。迈克尔·哈特尔的答案是正确的。在我的例子中,这是实现这一技巧的设置: 在nginx.conf中添加:
http {
# at the END of this segment!
client_max_body_size 1000m;
}
我确实在“http”级别指定了客户端最大体长:客户端最大体长1000M;客户机\主体\缓冲区\大小256k;对我来说,解决办法是将其移动到
http
块的底部,正如@rmuller在另一个回复中所建议的那样;当我把它放在开头的时候,它被完全忽略了。