dimanche 28 juin 2015

Nginx space on regex condition

I'm trying to block some user-agents on Nginx, and it's working great:

location /page {
  if ($http_user_agent ~* (badUserAgent1|badUserAgent2) ) {
   add_header 'Content-Type' 'text/plain';
   return 200 'Hello World';
  }
 }

But if I add a string with space, I get an error:

invalid condition "$http_user_agent"

Example:

location /page {
  if ($http_user_agent ~* (badUserAgent1|bad user agent 2) ) {
   add_header 'Content-Type' 'text/plain';
   return 200 'Hello World';
  }
 }

I tried to use apostrophes like this: ("badUserAgent1"|"bad user agent 2") without success.

Aucun commentaire:

Enregistrer un commentaire