Skip to content

Instantly share code, notes, and snippets.

@HaiwenZhang
Created February 17, 2017 04:11
Show Gist options
  • Save HaiwenZhang/c2cc59b68c6e1e2d1e9cc45dd1035c31 to your computer and use it in GitHub Desktop.
Save HaiwenZhang/c2cc59b68c6e1e2d1e9cc45dd1035c31 to your computer and use it in GitHub Desktop.
two port nginx config
upstream old_rails_puma {
server old_app:3000;
}
upstream new_rails_puma {
server new_app:4000
}
# Old Rails server config, listen 80 port
server {
listen 80;
root /app/old/public;
access_log /var/log/nginx/nginx.access.log;
error_log /var/log/nginx/nginx.error.log;
try_files $uri/index.html $uri @rails_puma;
location @old_rails_puma {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
# proxy_set_header X-Forwarded-Proto https;
proxy_pass http://old_rails_puma;
proxy_redirect off;
}
# static content
location ~ ^/(assets|img|js|javascripts|styles|stylesheets)/ {
access_log off;
# Per RFC2616 - 1 year maximum expiry
expires max;
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;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
# New Rails server config, listen 8080 port
server {
listen 8080;
root /app/new/public;
access_log /var/log/nginx/nginx.access.log;
error_log /var/log/nginx/nginx.error.log;
try_files $uri/index.html $uri @rails_puma;
location @new_rails_puma {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
# proxy_set_header X-Forwarded-Proto https;
proxy_pass http://new_rails_puma;
proxy_redirect off;
}
# static content
location ~ ^/(assets|img|js|javascripts|styles|stylesheets)/ {
access_log off;
# 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;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment