【发布时间】:2018-09-10 10:32:04
【问题描述】:
我正在尝试在 Memcached 中保存打包 (gzip) html 并从 nginx 中使用:
- 从memcached module 的memcached 加载html
- 如果已打包,则由 nginx gunzip module 解包
- 通过ssi module处理ssi插入
- 返回结果给用户
大多数情况下,配置工作,除了 ssi 步骤:
location / {
ssi on;
set $memcached_key "$uri?$args";
memcached_pass memcached.up;
memcached_gzip_flag 2; # net.spy.memcached use second byte for compression flag
default_type text/html;
charset utf-8;
gunzip on;
proxy_set_header Accept-Encoding "gzip";
error_page 404 405 400 500 502 503 504 = @fallback;
}
看起来,nginx 在通过 gunzip 模块解包之前进行 ssi 处理。
在结果 HTML 中,我看到未解析的 ssi 指令:
<!--# include virtual="/remote/body?argument=value" -->
nginx 日志中没有错误。
试过ssi_types * -- 没有效果
知道怎么解决吗?
nginx 1.10.3 (Ubuntu)
更新
已尝试在上游再添加一个。结果相同 =(
在日志中,我看到,在上游请求后应用了 ssi 过滤器,但没有检测到包含。
upstream memcached {
server localhost:11211;
keepalive 100;
}
upstream unmemcached {
server localhost:21211;
keepalive 100;
}
server {
server_name dev.me;
ssi_silent_errors off;
error_log /var/log/nginx/error1.log debug; log_subrequest on;
location / {
ssi on;
ssi_types *;
proxy_pass http://unmemcached;
proxy_max_temp_file_size 0;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location @fallback {
ssi on;
proxy_pass http://proxy.site;
proxy_max_temp_file_size 0;
proxy_http_version 1.1;
proxy_set_header Connection "";
error_page 400 500 502 503 504 /offline.html;
}
}
server {
access_log on;
listen 21211;
server_name unmemcached;
error_log /var/log/nginx/error2.log debug; log_subrequest on;
location / {
set $memcached_key "$uri?$args";
memcached_pass memcached;
memcached_gzip_flag 2;
default_type text/html;
charset utf-8;
gunzip on;
proxy_set_header Accept-Encoding "gzip";
error_page 404 405 400 500 502 503 504 = @fallback;
}
location @fallback {
#ssi on;
proxy_pass http://proxy.site;
proxy_max_temp_file_size 0;
proxy_http_version 1.1;
proxy_set_header Connection "";
error_page 400 500 502 503 504 /offline.html;
}
}
如果可能,我想避免使用动态 nginx 模块的解决方案
【问题讨论】:
-
你能先从配置中删除缓存,看看它是否有效吗?您应该一次使用一层来解决问题
-
没有缓存或没有 gzip 一切正常。但我需要 ssi =) 的 gziped 缓存
-
我已经看过了。使用 ssi 进行缓存工作正常
-
@demon101 如果你清除所有缓存,然后请求带有curl 的页面,而不使用任何更高级别的 UA,会发生什么?