有两个请求,hello和status,返回的类型都是text/plain, status是nginx自带的,hello是自己添加的模块,测试gzip,发现status返回结果压缩,而hello返回结果不压缩,返回内容都大于1字节,编译时也加了--with-http_gzip_static_module,实在费解:
nginx.conf配置如下:
gzip on; gzip_min_length 1; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 5; gzip_types text/plain application/x-javascript text/css application/xml text/javascript; gzip_vary on;
[root@localhost ~]# curl "http://127.0.0.1/hello" (说明hello是有数据返回的) hello_world, wahahahahahahhahahahahahahahahahaahahahahahahahahahahahahahahah
gzip测试结果:
[root@localhost ~]# curl -I -H"accept-encoding:gzip" "http://127.0.0.1/hello" (新增的模块) HTTP/1.1 200 OK
Server: nginx/1.9.8
Date: Mon, 11 Apr 2016 06:10:00 GMT
Content-Type: text/plain
Content-Length: 77
Connection: keep-alive
[root @localhost ~]# curl -I -H"accept-encoding:gzip" "http://127.0.0.1/status" (nginx自带的状态测试)
HTTP/1.1 200 OK
Server: nginx/1.9.8
Date: Mon, 11 Apr 2016 06:10:06 GMT
Content-Type: text/plain
Connection: keep-alive
Vary: Accept-Encoding
Content-Encoding: gzip
看代码两个模块实现几乎一样,但是gzip测试结果不一样,求解?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
首先,感谢您的回帖, 1.可能我没说清楚,问题中的hello不是自己写的,是引用深入浅出nginx里面的例子; 2.我用了本站点的helloworld例子,http://www.oschina.net/code/snippet_937163_26019#43351 重新实验,结果是一样的,hello依然不能返回压缩后的结果。 编译:./configure --prefix=/usr/local/nginx_gzip --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --add-module=/root/vmwareTmp/mytest 3.请问您实验结果是否可以? 注:本站的例子修改:if (!(r->method & NGX_HTTP_GET))改成 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) ,否则curl -I -H不允许。问题依旧。。。 ######站上hello模块代码啊
######status和hello的机制应该是有些许不同的,连日志都不一样,在没有添加日志情况下,hello的请求信息打出来了,而status并没有。。。 ######要疯了,干。。。######操作系统版本:Linux centos 2.6.32-504.el6.x86_64 ###### ngx_http_hello_handler 函数中, 添加:r->headers_out.content_type_len = sizeof("text/plain") - 1; 去掉:r->headers_out.content_length_n = content_length; ######