Created
September 18, 2017 04:56
-
-
Save kitsuyui/ca991dc918da8f87f2dda324bc711a7b to your computer and use it in GitHub Desktop.
備忘録: nginx でアクセス元 IP レンジに応じて Web アプリケーションを切り替える ref: http://qiita.com/kitsuyui/items/aefb3f301fd4f7004d81
This file contains hidden or 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
$ sudo service nginx configtest && sudo service nginx reload |
This file contains hidden or 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
upstream usual_server { | |
server 127.0.0.1:8080; | |
} | |
upstream testing_server { | |
server 127.0.0.1:8081; | |
} | |
geo $maintenance { | |
default 0; | |
# 許可したい IP レンジ | |
192.168.100.105/32 1; | |
} | |
server { | |
if ($maintenance = 0) { | |
set $target_proxy_server "usual_server"; | |
} | |
if ($maintenance = 1) { | |
set $target_proxy_server "testing_server"; | |
} | |
location / { | |
proxy_pass http://$target_proxy_server; | |
} | |
} |
This file contains hidden or 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
if ($maintenance = 1) { | |
location / { | |
proxy_pass http://$testing_server; | |
} | |
} | |
if ($maintenance = 0) { | |
location / { | |
proxy_pass http://$usual_server; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment