<% @path = "/etc/nginx/rubber/unicorn_nginx.conf" %> upstream unicorn_server { # This is the socket we configured in unicorn.rb server unix:/var/run/unicorn.sock fail_timeout=0; } server { listen 80; client_max_body_size 4G; server_name <%= [ rubber_env.domain, rubber_env.web_aliases ].flatten.compact.join(" ") %>; sendfile on; keepalive_timeout 65; # Location of our static files root <%= Rubber.root + "/public" %>; set $public <%= Rubber.root + "/public" %>; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; # If you don't find the filename in the static files # Then request it from the unicorn server if (!-f $request_filename) { proxy_pass http://unicorn_server; break; } location ~ ^/assets/ { expires 1y; add_header Cache-Control public; add_header ETag ""; break; } location ~ ^/uploads/ { expires 1y; add_header Cache-Control public; add_header ETag ""; ## optional upload anti-hotlinking rules #valid_referers none blocked mysite.com *.mysite.com; #if ($invalid_referer) { # return 403; #} # let NGINX serve images location ~* \.(gif|png|jpg|jpeg|bmp|tif|tiff)$ { try_files $uri =404; } location ~ /_optimized/ { try_files $uri =404; } # attachments must go through the rails application to get the right content-disposition header proxy_set_header X-Sendfile-Type X-Accel-Redirect; proxy_set_header X-Accel-Mapping $public/=/downloads/; proxy_pass http://unicorn_server; break; } try_files $uri @discourse; } location /downloads/ { internal; alias $public/; } location @discourse { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_pass http://unicorn_server; } # this rewrites all the requests to the maintenance.html # page if it exists in the doc root. This is for capistrano's # disable web task if (-f $document_root/system/maintenance.html) { rewrite ^(.*)$ /system/maintenance.html last; break; } error_page 500 502 503 504 /500.html; location = /500.html { root <%= Rubber.root + "/public" %>; } error_page 404 /404.html; location = /404.html { root <%= Rubber.root + "/public" %>; } }