1

I am really bad with regex. I am trying to do this in nginx:

stream {

    map $ssl_preread_server_name $name {
        api.dom1.com dom1_backend;
        *.dom2.com dom2_backend;
    }

    upstream dom1_backend {
        server api.dom1.com:443;
    }

    upstream dom2_api_backend {
        server *.dom3.com:443;
    }

    server {
        listen 443;
        proxy_pass $name;
        ssl_preread on;
    }
}

How do I get dom2 working? I just need to map a wildcard domain back to wildcard domain.

Mean anything *.dom2.com will go to *.dom3.com

2 Answers 2

3

In order to use hostnames you should specify the special hostnames parameter to map. This allows for asterisk wildcards to be interpreted in the manner you expect.

map $ssl_preread_server_name $name {
    hostnames;
    api.dom1.com dom1_backend;
    *.dom2.com dom2_backend;
}
3
  • Thanks! This works for the map block. What about the upstream block? Doesn't work with hostnames parameter. server *.dom3.com:443;
    – abubin
    Jul 3, 2020 at 2:46
  • @abubin Huh? That doesn't even make any sense. There's no such host. You have to name a specific server. Jul 3, 2020 at 3:01
  • oh..I wanted to make wildcard to wildcard. EG, aaa.dom2.com to aaa.dom3.com, bbb.dom2.com to bbb.dom3.com, x11.dom2.com to x11.dom3.com... is that even possible? Thanks.
    – abubin
    Jul 3, 2020 at 4:26
0

I think with map you may won't need upstream any more, try this:

stream {
    map $ssl_preread_server_name $name {
        hostnames;
        api.dom1.com dom1_backend;
        *.dom2.com   dom2_backend;
    }

    server {
        listen 443;
        listen 6443;
        proxy_pass $name:$server_port;
        ssl_preread on;
    }
}
1
  • what if their upstream has multiple hosts? Dec 19, 2020 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.