Skip to content

Instantly share code, notes, and snippets.

@cmather
Created November 30, 2012 20:31
Show Gist options
  • Save cmather/4178398 to your computer and use it in GitHub Desktop.
Save cmather/4178398 to your computer and use it in GitHub Desktop.
Example Nginx Config
map $uri $preferred_proto {
default "http";
~^/assets/ "none";
~^/signup "https";
~^/users "https";
~^/users/(.*)$ "https";
~^/login "https";
~^/sessions "https";
~^/api/(.*)$ "https";
~^/password_resets "https";
}
upstream unicorn {
server unix:/tmp/unicorn.emind.sock fail_timeout=0;
}
server {
listen 80 default deferred;
root /home/deployer/apps/emind/current/public;
if ($preferred_proto = "https") {
return 301 https://$http_host$request_uri;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_redirect off;
proxy_pass $scheme://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 70;
}
server {
listen 443 default_server ssl;
ssl_certificate /etc/ssl/certs/www_eventedmind_com.pem;
ssl_certificate_key /etc/ssl/private/www_eventedmind_com.key;
root /home/deployer/apps/emind/current/public;
if ($preferred_proto = "http") {
return 301 http://$http_host$request_uri;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 70;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment