【问题标题】:X-Content-Type-Options causes image to display as gibberish text [nginx]X-Content-Type-Options 导致图像显示为乱码文本 [nginx]
【发布时间】:2022-02-08 03:57:22
【问题描述】:

我已设置反向代理端口 8086。端口 8086 正在运行一个 javascript,以 webp 格式显示随机图像。如果我尝试访问域,它会将图像显示为乱码。如果我访问 ip 地址而不是域,它工作正常。

我发现more_set_headers "X-Content-Type-Options : nosniff" 导致图像显示为乱码。有没有办法仅删除特定站点的该设置?原因 X-Content-Type-Options : nosniff 设置为适用于所有站点。

nginx 配置

server {

    server_name sub.example.com www.sub.example.com;

    access_log /var/log/nginx/sub.example.com.access.log ;
    error_log /var/log/nginx/sub.example.com.error.log;
    

    add_header X-Proxy-Cache $upstream_cache_status;
    location / {
        proxy_pass http://xxx.xxx.xxx.xxx:8086/img;
        proxy_redirect      off;
        proxy_set_header X-Content-Type-Options "";
    }
}

如何从特定站点删除 X-Content-Type-Options : nosniff?

【问题讨论】:

    标签: nginx


    【解决方案1】:

    这可以通过“函数式”方式完成:始终使用 map{} 中的值添加标头。映射 $host $nosniff {myhost '';默认 nosniff;}

    【讨论】:

      猜你喜欢
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      • 2015-08-14
      • 2016-09-07
      • 2013-04-05
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      相关资源
      最近更新 更多