Skip to content

Instantly share code, notes, and snippets.

@balepc
Created March 22, 2010 21:52
Show Gist options
  • Save balepc/340575 to your computer and use it in GitHub Desktop.
Save balepc/340575 to your computer and use it in GitHub Desktop.
Typical nginx configuration
worker_processes 2; # Usually number of processors
error_log logs/error.log;
events {
worker_connections 2024;
}
http {
passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.5;
passenger_ruby /usr/local/bin/ruby;
passenger_max_pool_size 5; # Optional, should be configured in context of your environment
include mime.types;
default_type application/octet-stream;
client_max_body_size 100m;
sendfile on;
tcp_nopush on;
gzip on;
gzip_min_length 1100;
gzip_comp_level 8; # compression level 1..9
gzip_http_version 1.0;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\."; # IE6 fix
keepalive_timeout 500; # depends on your need
server { # This is optional, use this if you have
# config.action_controller.asset_host = "cdn%d.#{SITE_DOMAIN}"
listen 80;
expires max;
add_header Cache-Control public;
add_header Vary Accept-Encoding;
server_name cdn0.domain.com cdn1.domain.com cdn2.domain.com cdn3.domain.com;
root /opt/applications/app_name/current/public;
}
server {
listen 80;
server_name domain.com *.domain.com;
if ($host = 'domain.com') { # If you preffer www instead of plain domain
rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
}
root /opt/applications/app_name/current/public;
access_log /opt/applications/app_name/current/log/access.log;
error_log /opt/applications/app_name/current/log/error.log;
ssi on;
proxy_read_timeout 500;
if ($host ~* "^([^www][a-zA-Z]+)\.domain\.com$") { # redirect to special path for subdomains
rewrite ^/$ /messages/users/ last;
}
location / {
default_type text/html;
proxy_set_header X-Real-IP $remote_addr; # Ip behind proxy
if (-f $request_filename) {
expires max;
break;
}
if ($request_method = POST) {
passenger_enabled on;
break;
}
# Supports for maintenance.html
try_files /maintenance.html $uri $uri/index.html $uri.html @modrails;
}
location @large_upload {
passenger_enabled on;
}
location /data/public_files {
root /opt/applications/site_name/current/public;
}
location @modrails {
passenger_enabled on;
}
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