Skip to content

Instantly share code, notes, and snippets.

@JeanMertz
Forked from shapeshed/nginx_rails_3_1
Last active December 10, 2015 01:18
Show Gist options
  • Save JeanMertz/4358043 to your computer and use it in GitHub Desktop.
Save JeanMertz/4358043 to your computer and use it in GitHub Desktop.
upstream www {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/var/www/shared/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
root /var/www/current/public;
access_log /var/www/shared/log/nginx/access.log;
error_log /var/www/shared/log/nginx/error.log;
rewrite_log on;
if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS|PATCH)$ ){
return 405;
}
# if the request is for a static resource, nginx should serve it directly
# and add a far future expires header to it, making the browser
# cache the resource and navigate faster over the website.
location ~ ^/(assets)/.+-([0-9a-zA-Z])+\. {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location / {
try_files $uri/index.html $uri.html $uri @app;
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
error_page 403 /403.html;
}
location @www {
proxy_pass http://app.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location = /favicon.ico {
expires max;
add_header Cache-Control public;
}
location ~ \.php$ {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment