apache - 为什么nginx不转发Apache在代理模式下发送的Vary header?
问题描述
我正在使用 Plesk(似乎是 OVH 提供的 17.8.11)并且 nginx 被配置为代理。我的 PHP 脚本在浏览器接受时将图像返回为 WEBP 格式,否则返回原始格式(JPG 或 PNG)。
在 .htaccess 中,我返回标头Vary: Accept
,以便代理知道内容取决于Accept
标头。
在 Plesk 的 nginx 设置中,我只选中了“代理模式”选项,其他复选框被清除。当我获取Vary: Accept
不存在的图像时,我无法想象 nginx 不处理此标头,请帮我解决这个问题。
解决方案
I finally found the reason: I was not sending "Vary: Accept" header for ".webp" extension, only for ".jpg" and ".png". My URLs ends with .jpg or .png, never .webp and this is working good with Apache. Here was my htaccess directives:
<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>
To fix it I added .webp in URLs filter:
<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>
Now it's all good.
推荐阅读
- reactjs - 样式化的组件自定义道具在 typescript eslint 中返回 no-undef
- python - 如何使用循环调整参数?
- bash - 在bash脚本中删除字符串数组中的引号
- node.js - 从用户聊天中获取每个用户的最后一个文档 - mongoose
- try-catch - 尝试捕获块问题
- flutter - flutter run -d chrome --release 抛出错误 Missing index.html (Flutter)
- php - 无法从 URL PHP 中获取以 # 开头的 id
- ios - 为什么将 Core Data 与 CloudKit 一起使用时关系必须是可选的?
- java - 由于这个错误,我无法完成这个冒险故事
- python - 我们如何在 jsonpath_ng python 中使用正则表达式过滤器,它将 / 视为 SORT 方向。有什么选择吗?