【发布时间】:2018-02-03 06:33:42
【问题描述】:
拥有一个应该为 http 和 https 提供内容的服务器块:
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
include snippets/certificate.conf;
include snippets/ssl-params.conf;
root ...
}
是否可以只为同一服务器块中的 https 连接配置 gzip 压缩,还是我必须放弃它们?
编辑:
实际上可以检查位置块内的请求方案,如果等于 https,则将 gzip 设置为关闭:
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
include snippets/certificate.conf;
include snippets/ssl-params.conf;
location / {
if ($scheme = "https") {
gzip off;
}
try_files $uri $uri/ =404;
}
...
}
问题是在 if 块 https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
中只使用 rewrite 和 return 语句似乎是安全的【问题讨论】: