Nginx $upstream_http_content_type 正则问题


我通过 nginx 的 $upstream_http_content_type 判断类型是否是图片,代码如下:


 add_header X-Content-Type $upstream_http_content_type;

if ($upstream_http_content_type ~* ^image/(jpg|jpeg|pjpeg|png|x-png|gif|bmp|x-icon|webp|svg\+xml)) {
    return 301;
}

可结果是 X-Content-Type 倒是有了,却没有 301 跳转?

67f51f75gw1esjz1788c9j20fg07bq3o.jpg

理论上应该酱紫啊:

67f51f75gw1esjz4whqutj20cr04z0t1.jpg

求解,如何弄?

upstream_http_content_type 正则表达式 nginx

黑猫的骑士 10 years, 10 months ago

没细看哈 如果真是正则的问题 那就是你image后的斜线没有转义 ^image\/(jpg|jpeg|pjpeg|png|x-png|gif|bmp|x-icon|webp|svg\+xml)

我愛曬星星 answered 10 years, 10 months ago

Your Answer