What is the difference between Nginx ~ and ~* regexes?

For example:

if ($http_referer ~* www.foobar.net) {


if ($http_referer ~ www.foobar.net) {
  • In your example the ~* means that WWW.FOOBAR.NET as an uppercase referrer would be included in the following ruleset. Aug 28, 2022 at 19:18

2 Answers 2


~: If a tilde modifier is present, this location will be interpreted as a case-sensitive regular expression match.

~*: If a tilde and asterisk modifier is used, the location block will be interpreted as a case-insensitive regular expression match.


cduffin is correct.

Here is an example of using this regex for a location block to reject uri's that try to access a certain file type (assuming we are using try_files lower in the nginx config)

location ~* \.(txt|log|config)$ {
    return 403;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .