Created
April 16, 2017 12:02
-
-
Save mimikadze/27002e219c23bbec5a626a6a47f06129 to your computer and use it in GitHub Desktop.
Sample NGINX config for rails app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream application { | |
server unix:/tmp/example_puma.sock fail_timeout=0; | |
} | |
# Optional redirect | |
#server { | |
# listen 80; | |
# server_name www.DOMAIN default; | |
# return 301 $scheme://DOMAIN$request_uri; | |
#} | |
server { | |
listen 80; | |
server_name example.com default; | |
root /opt/boo-kit/current/public; | |
try_files $uri/index.html $uri @application; | |
location @application { | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_pass http://application; | |
access_log /var/log/nginx/example.access.log; | |
error_log /var/log/nginx/example.error.log; | |
} | |
location ~ ^/(assets|images|javascripts|stylesheets|swfs|system|uploads)/ { | |
gzip_static on; | |
expires max; | |
add_header Cache-Control public; | |
add_header Last-Modified ""; | |
add_header ETag ""; | |
open_file_cache max=1000 inactive=500s; | |
open_file_cache_valid 600s; | |
open_file_cache_errors on; | |
break; | |
} | |
client_max_body_size 10M; | |
keepalive_timeout 300; | |
error_page 500 502 504 /500.html; | |
error_page 503 @503; | |
location = /50x.html { | |
root html; | |
} | |
location = /404.html { | |
root html; | |
} | |
location @503 { | |
error_page 405 = /system/maintenance.html; | |
if (-f $document_root/system/maintenance.html) { | |
rewrite ^(.*)$ /system/maintenance.html break; | |
} | |
rewrite ^(.*)$ /503.html break; | |
} | |
if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS)$ ){ | |
return 405; | |
} | |
if (-f $document_root/system/maintenance.html) { | |
return 503; | |
} | |
location ~ \.(php|html)$ { | |
return 405; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment