Created
January 18, 2012 18:29
-
-
Save riywo/1634678 to your computer and use it in GitHub Desktop.
nginxでURIの先頭使ってbackend serverのportを決める
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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