Skip to content

Instantly share code, notes, and snippets.

@albertsun
Created December 16, 2011 01:07
Show Gist options
  • Save albertsun/1483907 to your computer and use it in GitHub Desktop.
Save albertsun/1483907 to your computer and use it in GitHub Desktop.
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#Say you have two apps, app_1 ...
upstream superbowl {
server 127.0.0.1:3005;
}
upstream oscars {
server 127.0.0.1:3004;
}
#and app_2.
upstream chad {
server 127.0.0.1:3000;
}
server {
listen 8080;
server_name *.localhostsvc.nytimes.com;
if ($host ~* "^(.+).localhostsvc.nytimes.com"){
set $sub $1;
}
# listen at localhostsvc.localhost.com:8080 and intercept all requests to /svc/int
location /svc/int {
rewrite /svc/int/([^/]+)/(.*) /$2 break;
proxy_pass http://$1/$2?$query_string;
proxy_set_header Host $host:$server_port;
proxy_redirect off;
}
# Here's the problem: many rails apps in development will refer to "/images/pretty.jpg".
# In this proxy set up, since we stripped off /svc/int so that the app can handle it
# without additional app logic, "/images" points to the wrong thing. So we look at the
# request, use that to figure out which app it came from and reappend the app route to
# our one-size fits all proxy.
location / {
if ($sub) {
rewrite /(.*) /svc/int/$sub/$1;
}
root html;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment