16

I'm trying to use nginx to proxy pass to two docker containers. Here is my upstream conf file:

upstream api_servers {
  server http://192.168.49.4:49155;
  server http://192.168.49.4:49156;
}

This is what I get trying to load it:

nginx: [emerg] invalid host in upstream "http://192.168.49.4:49155" in /etc/nginx/conf.d/api_upstream.conf:3
nginx: configuration file /etc/nginx/nginx.conf test failed

Once I removed the http:// prefixes the error stopped occuring. Why is that?

AD7six
  • 2,810
  • 2
  • 20
  • 23
user2108258
  • 303
  • 1
  • 3
  • 10

3 Answers3

23

The upstream block is a list of servers with optional status pooling and connection restrictions. The protocol used to join theses servers must be specified in the proxy_pass directive.

upstream api_servers {
    server 192.168.49.4:49155;
    server 192.168.49.4:49156;
}

server {

    [ ... ]

    location /foo/ {
        proxy_pass http://api_servers/;
    }

}
Xavier Lucas
  • 12,815
  • 2
  • 44
  • 50
2

Syntax: server address [parameters];The address can be specified as a domain name or IP address, with an optional port, or as a UNIX-domain socket path specified after the “unix:” prefix. I think you should like to look at "http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream".

xiaopihai
  • 41
  • 2
0

I think the host [api_servers] is not valid because underscore( _ ) is never valid character in a domain name. After removing ( _ ) in the above ngix config, it started working for me.

for example: upstream apiservers { server 192.168.49.4:49155; server 192.168.49.4:49156; }

server {

location /foo/ {
    proxy_pass http://apiservers/;
}

}