Created
August 8, 2022 10:20
-
-
Save cooka/05deda5c7c92354d9d2e7a3baed5c9b9 to your computer and use it in GitHub Desktop.
Nginx: use different backend based on HTTP header
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
upstream apache { | |
server 127.0.0.1:8080; | |
} | |
upstream staging { | |
server 127.0.0.1:8081; | |
} | |
upstream development { | |
server 127.0.0.1:8082; | |
} | |
# map to different upstream backends based on header | |
map $http_x_server_select $pool { | |
default "apache"; | |
staging "staging"; | |
dev "development"; | |
} | |
server { | |
listen 80; | |
server_name example.com; | |
location / { | |
proxy_pass http://$pool; | |
#standard proxy settings | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_redirect off; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_connect_timeout 600; | |
proxy_send_timeout 600; | |
proxy_read_timeout 600; | |
send_timeout 600; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment