我在 nginx 反向代理后面有一个 Web 应用程序(使用 Java 框架 Play 开发)。当我请求页面时,较大的 CSS 文件(Bootstrap.min.css 和 easyui.css)不会加载。Chrome 控制台显示net::ERR_CONTENT_LENGTH_MISMATCH
这些文件。实际上,Content-Length
bootstrap.min.css 的标头为 121260(约 118Ko),但只传输了 20,73Ko。
我的 Nginx 版本是 1.10.1(在我通过 Debian 测试版本之前是 1.2.1)。
下面是我的 nginx.conf 中未注释的部分(我禁用了 gzip,因为我读到该问题可能是由压缩引起的,但这并没有解决任何问题):
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip off;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我的 proxy.conf 文件(在 conf.d 中):
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header X-Powered-By;
client_max_body_size 16m;
client_body_buffer_size 128k;
client_header_buffer_size 64k;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 16k;
proxy_buffers 32 16k;
proxy_busy_buffers_size 64k;
proxy_cache_key "$scheme://$host$request_uri";
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cache:10m inactive=7d max_size=700m;
我的网络应用程序的配置文件:
server {
listen 80;
server_name foo.bar.net;
access_log /var/log/nginx/default.access.log;
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
location / {
proxy_http_version 1.1;
proxy_pass http://192.168.1.5:9002/;
proxy_cache off;
proxy_buffering off;
expires -1s;
}
location ^~ (^/admin|^/identification) {
proxy_pass http://192.168.1.5:9002;
}
error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 500 501 502 503 504 505 506 507 /error.html;
location = /error.html {
root /var/www/nginx-default;
}
}
nginx 错误日志:
2016/06/10 15:22:05 [error] 28538#28538: *2446 upstream prematurely closed connection while sending to client, client: 172.16.1.2, server: foo.bar.net, request: "GET /assets/bootstrap-3.3.6-dist/css/bootstrap.min.css HTTP/1.1", upstream: "http://192.168.1.5:9002/assets/bootstrap-3.3.6-dist/css/bootstrap.min.css", host: "foo.bar.net", referrer: "http://foo.bar.net/"