上游服务器中的 Nginx http 前缀

use*_*258 14 nginx centos vagrant

我正在尝试使用 nginx 代理传递给两个 docker 容器。这是我的上游 conf 文件:

upstream api_servers {
  server http://192.168.49.4:49155;
  server http://192.168.49.4:49156;
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试加载它的内容:

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
Run Code Online (Sandbox Code Playgroud)

一旦我删除了 http:// 前缀,错误就会停止发生。这是为什么?

Xav*_*cas 19

上游块是具有可选状态池和连接限制的服务器列表。必须在proxy_pass指令中指定用于加入这些服务器的协议。

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

server {

    [ ... ]

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

}
Run Code Online (Sandbox Code Playgroud)


小智 2

语法:服务器地址[参数];该地址可以指定为域名或IP地址,带有可选端口,也可以指定为\xe2\x80\x9cunix:\xe2\x80\x9d后指定的UNIX域套接字路径字首。我想你应该看看“ http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream ”。

\n