Skip to content

Instantly share code, notes, and snippets.

@s0what
Created May 9, 2012 07:10
Show Gist options
  • Save s0what/2642594 to your computer and use it in GitHub Desktop.
Save s0what/2642594 to your computer and use it in GitHub Desktop.
nginx config
user www www;
worker_processes 2;
pid /var/run/nginx.pid;
error_log /var/log/nginx/err.info.log info;
worker_rlimit_nofile 20046;
events {
use epoll;
worker_connections 20046;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
client_max_body_size 2m;
log_format combined_add_time 'IP:[ $remote_addr ] - $remote_user '
'"$request" $status $body_bytes_sent '
'REF:[ $http_referer ] HTTP_USER_AGENT:[ $http_user_agent ] '
' Host:[ $host ] [ $time_local ]';
error_log /var/log/nginx/http.error.log error;
sendfile on;
keepalive_timeout 10;
tcp_nopush on;
tcp_nodelay off;
gzip on;
gzip_min_length 500;
gzip_http_version 1.0;
gzip_proxied any;
gzip_comp_level 2;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript application/x-javascript
application/xml application/xml+rss application/atom+xml;
upstream app_server_jakarta {
server unix:/var/www/xxx/shared/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80 default_server;
server_name _;
return 403;
}
# xxx.com
server {
listen 80;
server_name www.xxx.com xxx.com;
root /var/www/xxx/current/public;
access_log /var/log/nginx/access.xxx.log combined_add_time;
if ($host = "xxx.com") {
rewrite ^(.*)$ http://www.xxx.com$1 permanent;
}
# Anti shit spider
if ( $http_user_agent ~* (Gootkit|auto-rooter|80legs|webcrawler|Toata|dragostea|Search17Bot|YoudaoBot|qihoobot|Sogou|heritrix|ZmEu|Morfeus|Netcraft|^Java|Commons-HttpClient|Wget|^PHP|Ruby|Python) ) {
return 403;
}
if ( $uri ~* (php|phpmyadmin|administrator) ) {
return 404;
}
if (-f $document_root/maintenance.html) {
rewrite ^(.*)$ /maintenance.html break;
}
try_files $uri/index.html $uri.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# send request to ruby app server
proxy_pass http://app_server_jakarta;
}
# location ~ .*\.(js|css|gif|jpg|jpeg|png|bmp|swf)$
# {
# #access_log off;
# expires 30d;
# }
location ~ ^/assets/ {
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}
location ~ ^/(assets)/ {
root /var/www/xxx/current/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
# error_page 404 /404.html;
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/xxx/current/public;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment