nginx转发到localhost 502错误网关

时间:2018-11-24 00:32:28

标签: docker nginx

我有nginx作为api的代理(localhost:5000)。我想将端口555上的请求转发到localhost5000。我将docker用于nginx和api应用程序。

docker-compose.yml

version: '3.6'

services:
  app:
    build:
      context:  ./server/xxx.Api
      dockerfile: Dockerfile
    network_mode: host

  proxy:
    build:
      context:  ./server/nginx
      dockerfile: Dockerfile
    ports:
      - "555:555"

nginx.conf:

server {
  listen 555;
  server_name localhost;
  location / {
    proxy_pass http://127.0.0.1:5000;
    proxy_set_header    Host             $host;
    proxy_set_header    X-Real-IP        $remote_addr;
    proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header    X-Client-Verify  SUCCESS;
    proxy_set_header    X-Client-DN      $ssl_client_s_dn;
    proxy_set_header    X-SSL-Subject    $ssl_client_s_dn;
    proxy_set_header    X-SSL-Issuer     $ssl_client_i_dn;
    proxy_read_timeout 1800;
    proxy_connect_timeout 1800;
  }
}

但是我没有使用5000端口的应用程序,而是从nginx获得了502 Bad Gateway。应用程序也在docker中。

如果我将请求转发到另一个网站

proxy_pass http://reddit.com;

一切正常。怎么了?

0 个答案:

没有答案