D
D
DennyD3142021-03-24 16:26:40
Nginx
DennyD314, 2021-03-24 16:26:40

How to get the server name from the upstream section from a variable in Nginx?

Hello!
There is a project deployed on two OpenShift clusters.
I am setting up an Nginx balancer between clusters.
Openshift routes work in Passthrought SSL termination mode.
In order for the service to open normally, hostname must be passed to NGINX proxy_ssl_name.

I'm trying something like this NGINX configuration:

upstream backend {
    server.com.one
    server.com.two max_fails ...
}

server {
    ...
    proxy_ssl_name $proxy_host;
    proxy_set_header Host $proxy_host;
    proxy_pass https://backend;
}


The problem is that the backend is passed in the $proxy_host variable, and not server.com.one, which is needed.

Is it possible to get the desired value in some variable?
Or pass multiple values ​​to proxy_ssl_name?
Or perhaps there is some fundamentally different solution within these technologies?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2021-03-25
@DennyD314

You can add an intermediate server block for each upstream and proxy through it.
More or less like this:

upstream backend {
    127.127.0.1:2000;
    127.127.0.2:2000 max_fails ...;
}

server {
    proxy_pass https://backend;
}

server {
    listen 127.127.0.1:2000;
    location / {
        proxy_pass https://server.com.one;
    }
}

server {
    listen 127.127.0.2:2000;
    location / {
        proxy_pass https://server.com.two;
    }
}

V
Viktor Taran, 2021-03-24
@shambler81

$host won't work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question