Skip to content

Instantly share code, notes, and snippets.

@bsa7
Last active May 3, 2016 05:06
Show Gist options
  • Save bsa7/908dce22ccb18528292cd7f91dbc6153 to your computer and use it in GitHub Desktop.
Save bsa7/908dce22ccb18528292cd7f91dbc6153 to your computer and use it in GitHub Desktop.
Rails puma nginx ssl
upstream site_name {
server unix:///home/me/projects/site_name/shared/tmp/sockets/site_name.sock;
}
# for redirecting to https version of the site
server {
listen 80;
rewrite ^(.*) https://$host$1 permanent;
}
# for redirecting to non-www version of the site
server {
listen 80;
server_name www.site_name.ru;
rewrite ^(.*) http://site_name.ru$1 permanent;
}
server {
listen 443 default ssl;
ssl on;
ssl_certificate /etc/nginx/ssl/site_name.ru.crt;
ssl_certificate_key /etc/nginx/ssl/site_name.ru.key;
server_name site_name.ru;
try_files $uri/index.html $uri.html $uri @site_name;
client_max_body_size 4m;
error_page 502 /502.html;
location = /502.html {
root /etc/nginx/error-pages;
}
location / {
proxy_pass http://site_name;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-SSL 1;
}
location ~* ^/assets/ {
root /home/me/projects/site_name/current/public; # I assume your app is located at that location
# Per RFC2616 - 1 year maximum expiry
expires 1y;
add_header Cache-Control public;
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
add_header Last-Modified "";
add_header ETag "";
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment