[英]Why does the file size matter for apache command Header append Vary User-Agent to trigger?
[英]Why nginx does not forward Vary header sent by Apache in proxy mode?
我正在使用 Plesk(似乎是 OVH 提供的 17.8.11)並且 nginx 被配置為代理。 當瀏覽器接受時,我的 PHP 腳本將圖像返回為 WEBP 格式,否則返回原始格式(JPG 或 PNG)。
在 .htaccess 中,我返回標頭Vary: Accept
以便代理知道內容取決於Accept
標頭。
在 Plesk 的 nginx 設置中,我只選中了“代理模式”選項,其他復選框被清除。 當我獲取圖像時Vary: Accept
不存在,我無法想象 nginx 不處理這個頭,請幫我弄清楚。
對於Vary:
被允許和nginx的理解頭,需要gzip on
和gzip_vary on
在您的設置/etc/nginx/nginx.conf
。
Plesk 實際上有關於它的文檔,您是否查看過 Plesk 支持網站? https://support.plesk.com/hc/en-us/articles/213380049-How-to-enable-disable-gzip-compression-in-nginx-on-a-Plesk-server
順便說一下,您的 Plesk 版本很舊,我建議您更新它。
我終於找到了原因:我沒有為“.webp”擴展名發送“Vary:Accept”標頭,只為“.jpg”和“.png”發送。 我的 URL 以 .jpg 或 .png 結尾,從不以 .webp 結尾,這在 Apache 中運行良好。 這是我的 htaccess 指令:
<IfModule mod_setenvif.c>
SetEnvIf Request_URI "\.(jpe?g|png)$" REQUEST_image
</IfModule>
<IfModule mod_headers.c>
Header append Vary Accept env=REQUEST_image
</IfModule>
為了修復它,我在 URLs 過濾器中添加了 .webp:
<IfModule mod_setenvif.c>
SetEnvIf Request_URI "\.(jpe?g|png|webp)$" REQUEST_image
</IfModule>
<IfModule mod_headers.c>
Header append Vary Accept env=REQUEST_image
</IfModule>
現在一切都好了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.