Skip to content

Instantly share code, notes, and snippets.

@hn-support
Created January 8, 2021 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hn-support/3d0ec225e7fd49e6996377e48996f57c to your computer and use it in GitHub Desktop.
Save hn-support/3d0ec225e7fd49e6996377e48996f57c to your computer and use it in GitHub Desktop.
# You can whitelist request that should be exempt from the development
# basic auth.
# It's possible to whitelist request based on their IP address, range,
# User-Agent, or by the requested URL.
# Please note though, that google and bing bots will always remain
# blocked on development nodes!
# Both IP addresses and IP ranges can be whitelisted here.
geo $development_exceptions_ip {
default "Development restricted area";
127.0.0.1/32 "off";
}
# It's also possible to whitelist specific user agents
map $http_user_agent $development_exceptions_ua {
default $development_exceptions_ip;
~*(magereport|letsencrypt) "off";
}
# You can exclude specific URL's from the development
# basic auth.
# The whitelist is based on the entire request.
# If you wish to whitelist an entire path, you'll need
# to use a regular expression.
map $request_uri $development_exceptions {
default $development_exceptions_ua;
/robots.txt "off";
# ~^(/index\.php)/rest/V1 "off";
}
@andy-igoo
Copy link

andy-igoo commented Feb 12, 2021

@hn-support On the last example $development_exceptions_ua is caused an error:

I tested with:

# You can exclude specific URL's from the development
# basic auth.
# The whitelist is based on the entire request.
# If you wish to whitelist an entire path, you'll need
# to use a regular expression.
map $request_uri $development_exceptions {
        default $development_exceptions;

        /robots.txt       "off";
      # ~^(/index\.php)/rest/V1 "off";
}

@Cieper
Copy link

Cieper commented Mar 25, 2021

Hey @andy-igoo ! Thanks for the comment. This snipped was made to work if you use all three options, as they 'chain' on to each other. I'll see about expanding the docs to point that out, as without it you indeed need to change the snippet to what yours read.

@arnoudhgz
Copy link

I tried to allow a user agent, "user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/85.0.4183.121 Safari/537.36 (compatible; Cloudflare SpeedTest/1.0; +https://blog.cloudflare.com/new-speed-page/)"

I used this statement:

map $http_user_agent $development_exceptions_ua {
        default $development_exceptions_ip;

        ~*(Cloudflare) "off";
}

But it does not allow the user agent

@klau85
Copy link

klau85 commented Feb 29, 2024

Hi,
can you give an example how i can whitelist a url like https://example.com/api/<> ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment