Score:0

Nginx distribute traffic based on hostname for both http and https

us flag

I'm currently using nginx to forward ssl traffic like this:

stream {
    map $ssl_preread_server_name $name {
        host1.org host1;
        default host2;
    }

    upstream host1 {
        server host1:443;
    }

    upstream host2 {
        server host2:443;
    }

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

I would like to extend this so that HTTP traffic (port 80) is forwarded as well.

I'm not sure if this is even possible with the stream module (because the Host header needs to be inspected), or if the http module needs to be used.

In the latter case, is there a smart option on how to unify this in a way that I do not need to duplicate the hostname->target mapping?

Michael Hampton avatar
cz flag
Why don't you just use normal server blocks?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.