Skip to content

Instantly share code, notes, and snippets.

@philsmy
Created April 11, 2015 06:11
Show Gist options
  • Save philsmy/03dc259de0b8b821638b to your computer and use it in GitHub Desktop.
Save philsmy/03dc259de0b8b821638b to your computer and use it in GitHub Desktop.
server {
listen 80;
server_name domain1.ca;
return 301 https://www.domain1.com$request_uri;
}
server {
listen 80;
server_name domain1.com;
return 301 https://www.domain1.com$request_uri;
}
server {
listen 80;
server_name www.domain1.com;
return 301 https://www.domain1.com$request_uri;
}
server {
listen 443 ssl;
server_name www.domain1.com;
ssl_certificate /etc/ssl/certs/domain1.com.chained.crt;
ssl_certificate_key /etc/ssl/private/domain1.com.key;
server_name www.domain1.com;
root <%= Rubber.root + "/public" %>;
access_log <%= rubber_env.nginx_log_dir %>/domain1-access.log main;
error_log <%= rubber_env.nginx_log_dir %>/domain1-error.log notice;
keepalive_timeout 5;
# skip feed images calls
location ~* ^/feed_images/ {
break;
}
# this rewrites all the requests to the maintenance.html
# page if it exists in the doc root. This is for capistrano's
# disable web task
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root <%= Rubber.root + "/public" %>;
}
error_page 404 /404.html;
location = /404.html {
root <%= Rubber.root + "/public" %>;
}
location ~ \.(aspx|php|jsp|cgi)$ {
return 410;
}
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# If you don't find the filename in the static files
# Then request it from the unicorn server
try_files $uri/index.html $uri.html $uri @unicorn;
}
location @unicorn {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn_server;
}
}
# domain 2
server {
listen 80;
server_name domain2.com;
return 301 $scheme://www.domain2.com$request_uri;
}
server {
listen 80;
server_name www.domain2.com;
access_log <%= rubber_env.nginx_log_dir %>/domain2-access.log main;
error_log <%= rubber_env.nginx_log_dir %>/domain2-error.log notice;
root <%= Rubber.root + "/public" %>;
location / {
try_files $uri @unicorn;
}
location = /robots.txt {
alias <%= Rubber.root + "/public/domain2_robots.txt" %>;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
recursive_error_pages on;
error_page 404 /lln_400.html;
error_page 500 502 504 /lln_400.html;
error_page 503 @503;
location @503 {
rewrite ^(.*)$ /system/maintenance.html break;
}
# Since location blocks are usually preferred to "if"'s, this is a little better
location ~ \.(aspx|php|jsp|cgi)$ {
return 410;
}
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_redirect off;
# This passes requests to unicorn, as defined in /etc/nginx/nginx.conf
proxy_pass http://unicorn_server;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment