Skip to content

Instantly share code, notes, and snippets.

@theY4Kman
Forked from anonymous/gist:5935312
Last active December 19, 2015 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theY4Kman/5935315 to your computer and use it in GitHub Desktop.
Save theY4Kman/5935315 to your computer and use it in GitHub Desktop.
nginx configuration which redirects based on the Host header. I use this in combination with a hosts file directing "myd" and "int" to localhost (or my workstation's IP if on a different computer) to allow cross-browser shortcuts to webapps not requiring a port. This means I can type "int/mypage" in Chrome, Firefox, IE, etc and be redirected to …
server {
if ($host = 'int') {
set $test I;
}
if ($host = 'myd') {
set $test M;
}
if ($remote_addr = '127.0.0.1') {
set $test '${test}L';
}
if ($remote_addr != '127.0.0.1') {
set $test '${test}R';
}
if ($test = IL) {
rewrite ^(.*)$ http://localhost:5050$1 break;
}
if ($test = IR) {
rewrite ^(.*)$ http://10.0.40.150:5050$1 break;
}
if ($test = ML) {
rewrite ^(.*)$ http://localhost:5051$1 break;
}
if ($test = MR) {
rewrite ^(.*)$ http://10.0.40.150:5051$1 break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment