Skip to content

Instantly share code, notes, and snippets.

@dukejones
Last active July 29, 2020 23:18
Show Gist options
  • Save dukejones/9e4b54066ec28067274ec9a4c35e7b97 to your computer and use it in GitHub Desktop.
Save dukejones/9e4b54066ec28067274ec9a4c35e7b97 to your computer and use it in GitHub Desktop.
Nginx configuration for Rails app with Puma unix socket
# This file is prior to installing Certbot.
# Don't use HTTP Basic Auth without SSL!
# Redirect www requests to non-www host
server {
server_name www.myserver.com www.mysvr.com;
return 301 $scheme://myserver.com$request_uri;
}
# Upstream server (Puma socket)
upstream puma {
server unix:/srv/app/shared/tmp/sockets/puma.sock fail_timeout=0;
# server 127.0.0.1:9292;
}
server {
auth_basic "Administrator’s Area";
auth_basic_user_file htpasswd;
root /srv/app/current/public;
# direct to maintenance if this file exists
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
# assets caching
location ~ ^/(assets|packs/js)/ {
access_log off;
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;
}
try_files $uri @puma;
location @puma {
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;
proxy_pass http://puma;
#proxy_http_version 1.1;
}
error_page 500 502 503 504 /500.html;
keepalive_timeout 10;
location = /favicon.ico {
expires max;
add_header Cache-Control public;
}
server_name myserver.com mysvr.com; # http2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment