qbbrtg
Last Updated: February 25, 2016
·
1.461K
· caherrerapa

Unicorn + Nginx setup with SSL

Please change "@" for @ (lazy to fix it at this time of the week)

upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/var/www/site.com/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {

listen 80;
listen 443 ssl;

server_name www.site.com;

# Application root, as defined previously
root /var/www/site.com/current/public;

try_files $uri/index.html $uri "@"app;

ssl_certificate /etc/ssl/certs/site_com.pem;
ssl_certificate_key  /etc/ssl/certs/site_com.key;

ssl_protocols  SSLv2 SSLv3 TLSv1;
ssl_ciphers  HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers   on;

if ($scheme = http) {
    rewrite ^ https://$server_name$request_uri permanent;
}
location "@"app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_redirect off;
    if (!-f $request_filename) {
        proxy_pass http://app;
        break; 
    }
}

error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}