NGINX not equal to

2020-03-12 03:06发布

A client wants me to block access to a page unless the http_user_agent = xxx.

Is there a way to do this? I was thinking of an if else or if not function but this doesn't seem to exist.

If I wanted to block a user agent I could do the below but is there a way to only allow that user agent?

if ($http_user_agent ~* (xxx) ) {
   return 403; 
}

标签: nginx
1条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-03-12 03:44

Use the !~* operator which is the negated version of ~*.

See this document for details.

查看更多
登录 后发表回答