Skip to content

Instantly share code, notes, and snippets.

@riywo
Created January 18, 2012 18:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riywo/1634678 to your computer and use it in GitHub Desktop.
Save riywo/1634678 to your computer and use it in GitHub Desktop.
nginxでURIの先頭使ってbackend serverのportを決める
http {
map $uri $backend_port {
include port_map;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
server {
listen 80;
server_name example.com;
if ($request_uri ~ ^/[^/]+/(.*)$) {
set $new_uri $1;
}
location / {
proxy_pass http://127.0.0.1:$backend_port/$new_uri;
}
}
}
default 5000;
~^/ikachan(/.*|)$ 5001; # http://example.com/ikachan/hoge -> http://localhost:5001/hoge
~^/cloudforecast(/.*|)$ 5002; # http://example.com/cloudforecast/fuga -> http://localhost:5002/fuga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment