stream server name question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

stream server name question

Louis Garcia
I am able to use $ssl_preread_server_name to get the server name. This is with https requests. Is there a corresponding embedded variable for http requests? I would like to setup streams to different backend servers based on http requests. Example below works for https but not http.
Thanks.

stream {
        map $ssl_preread_server_name $name {
                                            plex.montclaire.lan app1;
                                            transmission.montclaire.lan app2;
                                            default default;
                                           }
        upstream app1 {
                       server 127.0.0.1:32400 max_fails=3 fail_timeout=10s;
                      }
        upstream app2 {
                       server 127.0.0.1:9091 max_fails=3 fail_timeout=10s;
                      }
        server {
                listen 172.16.0.5:80;
                listen 172.16.0.5:443;
                proxy_pass $name;
                ssl_preread on;
               }
       }


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: stream server name question

Phillip Odam

Hi Louis

The variable I think you're looking for is $host - http://nginx.org/en/docs/http/ngx_http_core_module.html#variables


On 8/26/19 8:55 PM, Louis Garcia wrote:
I am able to use $ssl_preread_server_name to get the server name. This is with https requests. Is there a corresponding embedded variable for http requests? I would like to setup streams to different backend servers based on http requests. Example below works for https but not http.
Thanks.

stream {
        map $ssl_preread_server_name $name {
                                            plex.montclaire.lan app1;
                                            transmission.montclaire.lan app2;
                                            default default;
                                           }
        upstream app1 {
                       server 127.0.0.1:32400 max_fails=3 fail_timeout=10s;
                      }
        upstream app2 {
                       server 127.0.0.1:9091 max_fails=3 fail_timeout=10s;
                      }
        server {
                listen 172.16.0.5:80;
                listen 172.16.0.5:443;
                proxy_pass $name;
                ssl_preread on;
               }
       }


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: stream server name question

Louis Garcia
Does not work.

stream {
        map $host $name {
                                    plex.montclaire.lan app1;
                                    transmission.montclaire.lan app2;
                                    default default;
                                   }
        upstream app1 {
                       server 127.0.0.1:32400 max_fails=3 fail_timeout=10s;
                      }
        upstream app2 {
                       server 127.0.0.1:9091 max_fails=3 fail_timeout=10s;
                      }
        server {
                listen 172.16.0.5:80;
                listen 172.16.0.5:443;
                proxy_pass $name;
                ssl_preread on;
               }
       }

nginx[31436]: nginx: [emerg] unknown "host" variable
nginx[31436]: nginx: configuration file /etc/nginx/nginx.conf test failed

On Mon, Aug 26, 2019 at 9:06 PM Phillip Odam <[hidden email]> wrote:

Hi Louis

The variable I think you're looking for is $host - http://nginx.org/en/docs/http/ngx_http_core_module.html#variables


On 8/26/19 8:55 PM, Louis Garcia wrote:
I am able to use $ssl_preread_server_name to get the server name. This is with https requests. Is there a corresponding embedded variable for http requests? I would like to setup streams to different backend servers based on http requests. Example below works for https but not http.
Thanks.

stream {
        map $ssl_preread_server_name $name {
                                            plex.montclaire.lan app1;
                                            transmission.montclaire.lan app2;
                                            default default;
                                           }
        upstream app1 {
                       server 127.0.0.1:32400 max_fails=3 fail_timeout=10s;
                      }
        upstream app2 {
                       server 127.0.0.1:9091 max_fails=3 fail_timeout=10s;
                      }
        server {
                listen 172.16.0.5:80;
                listen 172.16.0.5:443;
                proxy_pass $name;
                ssl_preread on;
               }
       }


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: stream server name question

Phillip Odam

Not inside the stream it won't... you'll need the map to at least be inside http and probably server.

Phillip Odam
Principal Engineer, RosettaHealth
o: 202.350.4343
a: 2 Wisconsin Circle, Chevy Chase, MD
Connecting a Whole World of Healthcare
On 8/26/19 10:05 PM, Louis Garcia wrote:
Does not work.

stream {
        map $host $name {
                                    plex.montclaire.lan app1;
                                    transmission.montclaire.lan app2;
                                    default default;
                                   }
        upstream app1 {
                       server 127.0.0.1:32400 max_fails=3 fail_timeout=10s;
                      }
        upstream app2 {
                       server 127.0.0.1:9091 max_fails=3 fail_timeout=10s;
                      }
        server {
                listen 172.16.0.5:80;
                listen 172.16.0.5:443;
                proxy_pass $name;
                ssl_preread on;
               }
       }

nginx[31436]: nginx: [emerg] unknown "host" variable
nginx[31436]: nginx: configuration file /etc/nginx/nginx.conf test failed

On Mon, Aug 26, 2019 at 9:06 PM Phillip Odam <[hidden email]> wrote:

Hi Louis

The variable I think you're looking for is $host - http://nginx.org/en/docs/http/ngx_http_core_module.html#variables


On 8/26/19 8:55 PM, Louis Garcia wrote:
I am able to use $ssl_preread_server_name to get the server name. This is with https requests. Is there a corresponding embedded variable for http requests? I would like to setup streams to different backend servers based on http requests. Example below works for https but not http.
Thanks.

stream {
        map $ssl_preread_server_name $name {
                                            plex.montclaire.lan app1;
                                            transmission.montclaire.lan app2;
                                            default default;
                                           }
        upstream app1 {
                       server 127.0.0.1:32400 max_fails=3 fail_timeout=10s;
                      }
        upstream app2 {
                       server 127.0.0.1:9091 max_fails=3 fail_timeout=10s;
                      }
        server {
                listen 172.16.0.5:80;
                listen 172.16.0.5:443;
                proxy_pass $name;
                ssl_preread on;
               }
       }


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: stream server name question

Francis Daly
In reply to this post by Louis Garcia
On Mon, Aug 26, 2019 at 08:55:31PM -0400, Louis Garcia wrote:

Hi there,

> I am able to use $ssl_preread_server_name to get the server name. This is
> with https requests. Is there a corresponding embedded variable for http
> requests?

No.

"stream" does not know about http or https.

"stream" knows about tcp and ssl (and udp).

$ssl_preread_server_name is the ssl name, not the https name -- the
difference might seem subtle, but it is important here.

If you want to proxy based on https name (or http name), use "http" not
"stream".

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx