Skip to content

Instantly share code, notes, and snippets.

@sanmai
Last active December 26, 2023 01:35
Show Gist options
  • Save sanmai/10341223 to your computer and use it in GitHub Desktop.
Save sanmai/10341223 to your computer and use it in GitHub Desktop.
Hide referer header for outbound links with the power of nginx. For this to work you must use it within a https-enabled server.
# Usage:
# https://www.example.com/hide-referer?http://en.wikipedia.org/wiki/HTTP_referer
server {
server_name www.example.com;
listen 80;
listen 443 ssl;
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
# ssl_... etc
location = /hide-referer {
if ($args = "") {
return 404;
}
# only works over https
if ($ssl_session_id = "") {
return 404;
}
add_header X-Robots-Tag "noindex, nofollow";
add_header Content-Type "text/html; charset=us-ascii";
add_header Refresh "1; url=$args";
return 200 "<title></title><style>html,body{margin:0;min-height:100%;background:url(https://www.google.com/images/loading.gif) center no-repeat;}</style><body>";
}
# and so forth
}
@alirezarezamand
Copy link

Thanks you

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