About Conditional Authentication with Nginx

For the staging website you can conditionally require authentication based on the user agent. Here is an example of nginx settings:

map $http_user_agent $authentication {
    default "Access Restricted";
    "~^Facebot" "off";
    "~^Twitterbot" "off";
    "~^Google \(\+https://developers.google.com/\+/web/snippet/\)" "off";
    "~^Python-urllib" "off";
    "~.+?googleimageproxy" "off";
    "~^WeasyPrint" "off";
}

server {
    # ...
    location / {
        # ...
        auth_basic $authentication;
        auth_basic_user_file /etc/nginx/.htpasswd;
    }
}

This allows the website to be accessed by Facebook, Twitter, and Google logins, also by Python requests, and WeasyPrint library, but requires authentication for all other requests.

Tips and Tricks Programming Dev Ops Architecture nginx WeasyPrint