Skip to content

Instantly share code, notes, and snippets.

@altan-me
Created January 29, 2016 01:44
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 altan-me/a87ef114f71c437aa212 to your computer and use it in GitHub Desktop.
Save altan-me/a87ef114f71c437aa212 to your computer and use it in GitHub Desktop.
Basic Virtual-hosts file
#altan.me
server {
listen 80;
server_name altan.me;
root /var/www/altan.me;
index index.html index.php;
#Acces logs
access_log /var/log/nginx/altan.me.log;
##Removes www.
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
##Location + Removes .html
location / {
rewrite (.*)\.html $1 permanent;
try_files $uri.html $uri/ /;
limit_req zone=app burst=50;
}
## Only allow GET and HEAD request methods
if ($request_method !~ ^(GET|HEAD)$ ) {
return 444;
}
## Deny illegal Host headers
if ($host !~* ^(altan.me|www.altan.me)$ ) {
return 444;
}
## Deny certain User-Agents (case insensitive)
## The ~* makes it case insensitive as opposed to just a ~
if ($http_user_agent ~* (Baiduspider|Jullo) ) {
return 444;
}
## Deny certain Referers (case insensitive)
## The ~* makes it case insensitive as opposed to just a ~
if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|sex|teen|video|webcam|zippo) ) {
return 444;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment