Skip to content

Instantly share code, notes, and snippets.

@Lax
Last active January 4, 2021 06:33
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 Lax/b7f57a14e8d1ec40a8ff808722ab870f to your computer and use it in GitHub Desktop.
Save Lax/b7f57a14e8d1ec40a8ff808722ab870f to your computer and use it in GitHub Desktop.
User-Agent based ACL - conditional redirecting rules
log_format client_ip "$remote_addr";
map $http_user_agent $whitelist_ua {
default 1;
"~*curl" 0;
}
server {
listen 80;
access_log off;
if ($whitelist_ua) {
rewrite ^/.* https://v.mib.cc redirect;
}
location / {
access_log /var/log/nginx/client_ip.log client_ip;
return 200 "OK\nHello world!\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment