Skip to content

Instantly share code, notes, and snippets.

@johngrimes
Created June 2, 2010 06:47
Show Gist options
  • Save johngrimes/422039 to your computer and use it in GitHub Desktop.
Save johngrimes/422039 to your computer and use it in GitHub Desktop.
Nginx Rails app configuration
upstream unicorn-myapp { server 127.0.0.1:3000; }
server {
server_name myapp.com;
rewrite ^(.*) http://www.myapp.com$1 permanent;
}
server {
listen *:80;
server_name www.myapp.com;
root /var/www/sites/myapp/current/public;
access_log /var/www/sites/myapp/shared/log/access.log;
error_log /var/www/sites/myapp/shared/log/error.log;
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_hide_header X-Runtime;
proxy_redirect off;
try_files $uri @rails;
location @rails { proxy_pass http://unicorn-myapp; }
location @rails_expiry { expires 1y; proxy_pass http://unicorn-myapp; }
location ~ ^/(images|javascripts|stylesheets)/ { try_files $uri @rails_expiry; }
}
user www www;
worker_processes 4;
error_log /var/www/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
access_log /var/www/log/nginx/access.log;
include mime.types;
default_type application/octet-stream;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 65;
client_max_body_size 20m;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_vary on;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript application/json;
include /usr/local/nginx/sites-enabled/*;
}
@johngrimes
Copy link
Author

The app is hosted at /var/www/sites/myapp/current (or at a location symlinked to this). The root is the public directory within the Rails app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment