Welcome! Log In Create A New Profile

Advanced

How to proxy_pass based on HTTP headers?

Posted by martinszeltins 
How to proxy_pass based on HTTP headers?
December 20, 2020 06:58AM
I'm wondering how I can use HTTP headers and based on those headers I would like to proxy_pass it to different servers?

For example if the HTTP "accept" header is set to "text/html" then I want to proxy_pass to server 1, and otherwise to server 2.

I'm looking for something like this but don't know how to do it.

server {
listen 80;
server_name www.test.io;

location / {
IF HTTP HEADER accept == "text/html" {
proxy_pass http://your_server_ip:443;
} else {
proxy_pass http://your_server_ip:8080;
}
}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 245
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready