Skip to content

Instantly share code, notes, and snippets.

@johnmcaliley
Created July 8, 2011 15:02
Show Gist options
  • Save johnmcaliley/1072030 to your computer and use it in GitHub Desktop.
Save johnmcaliley/1072030 to your computer and use it in GitHub Desktop.
sample nginx config for rails with Thin app server
user nobody;
worker_processes 1;
error_log /usr/local/nginx/logs/error.log warn;
events {
worker_connections 1024;
}
http {
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_comp_level 2;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
#You point to thin instances and ports they are running on here
upstream thin {
server 127.0.0.1:8200;
server 127.0.0.1:8201;
server 127.0.0.1:8202;
}
server {
client_max_body_size 2M;
listen 80;
server_name yourdomain.com;
#server_name localhost;
root /rails_apps/my_rails_app/current/public;
index index.html index.htm;
location / {
proxy_buffer_size 4k;
proxy_buffers 8 32k;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_read_timeout 240;
if (-f $request_filename) {
break;
}
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
# any request not in the above 3 conditions is forwarded to Thins
if (!-f $request_filename) {
proxy_pass http://thin;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment