search

Home  >  Q&A  >  body text

Regular expression - Nginx $upstream_http_content_type regular expression problem

I use nginx's $upstream_http_content_type to determine whether the type is an image. The code is as follows:

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;
}

But the result is that X-Content-Type is present, but there is no 301 jump?

Theoretically it should be Jiang Zi:

How to solve it?

世界只因有你世界只因有你2752 days ago875

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 17:26:03

    I didn’t look carefully. If it’s really a regular issue, it’s because the slash after your image is not escaped^image/(jpg|jpeg|pjpeg|png|x-png|gif|bmp|x-icon|webp|svg+xml)

    reply
    0
  • Cancelreply