使用Nginx + Gzip + Unicorn时缺少Content-Length标头 [英] Missing Content-Length header when using Nginx + Gzip + Unicorn
本文介绍了使用Nginx + Gzip + Unicorn时缺少Content-Length标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在nginx中使用gzip时,我不知道为什么会缺少http响应"Content-Length header",我真的被卡住了,请有人帮帮我,非常感谢! 这是我的配置文件,
I don't know why http response is missed "Content-Length header" when I use gzip in nginx, i'm really getting stuck,please somebody help me, thank you so much! this is my config file,
nginx.conf
用户无人无人; worker_processes 8;
user nobody nobody ; worker_processes 8;
events {
worker_connections 1024;
accept_mutex on; # "on" if nginx worker_processes > 1
use epoll; # enable for Linux 2.6+
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
upstream backend-unicorn {
server unix:/tmp/unicorn_app.sock fail_timeout=0;
#server localhost:5000;
}
#access_log logs/access.log main;
sendfile on;
keepalive_timeout 100;
gzip on;
gzip_static on;
gzip_proxied any;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain application/zip text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image$
server {
listen 8080;
server_name misago;
access_log /var/log/nginx/unicorn.access.log main;
client_max_body_size 64M;
location /uploads/ {
root /usr/local/rails_apps/me_management_tool/current/public/uploads;
break;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
推荐答案
下面是一个高性能的Nginx解决方案,用于将x-file-size
标头添加到Gzip响应中.此处有完整讨论: https://github.com/AnthumChris/fetch-progress-指标/问题/13
Below is a performant Nginx solution to add x-file-size
header to Gzip responses. Full discussion here: https://github.com/AnthumChris/fetch-progress-indicators/issues/13
location / {
## Nginx Lua module must be installed https://docs.nginx.com/nginx/admin-guide/dynamic-modules/lua/
## https://github.com/openresty/lua-nginx-module#header_filter_by_lua
header_filter_by_lua_block {
function file_len(file_name)
local file = io.open(file_name, "r")
if (file == nil) then return -1 end
local size = file:seek("end")
file:close()
return size
end
ngx.header["X-File-Size"] = file_len(ngx.var.request_filename);
}
}
这篇关于使用Nginx + Gzip + Unicorn时缺少Content-Length标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文