Skip to content

Instantly share code, notes, and snippets.

@hijak
Created November 1, 2013 09:18
Show Gist options
  • Save hijak/7262937 to your computer and use it in GitHub Desktop.
Save hijak/7262937 to your computer and use it in GitHub Desktop.
Nginx Useful location entry's
###only allow GET and HEAD requests (if request method IS NOT get or head then return 405 error)
if ($request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
###deny other host headers (ref scams) (if the host is not mydomain return 405 error)
if ($host !~* ^(mydomain.com|www.mydomain.com)$ ) {
return 405;
}
###deny certain user agents (if user agent is then return 405 error)
if ($http_user_agent ~* (Baiduspider|Jullo) ) {
return 405;
}
###deny dodgy referers (case insensative)
if ($http_referer ~* (dodgy|bad|ugly|viagra|porn) ) {
return 405;
}
###redirect http://www.bleh to http://bleh
if ($host = 'www.bleh.com' ) {
rewrite ^/(.*)$ http://bleh.com/$1 permanent;
}
###deny image hijacking/stealing
location ~* (\.jpg|\.png|\.css)$ {
if ($http_referer !~ ^(http://mydomain.com) ) {
return 405;
}
}
###Restricted access to secure directory with password or by localhost
location ^~ /secure/ {
allow 127.0.0.1/32;
allow 10.8.0.0/24;
deny all;
auth_basic "GO AWAY";
auth_basic_user_file /var/www/html/secure/access_list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment