nginx:nginx反向代理在服务器中有效,但在本地主机上不可用

问题描述 投票:0回答:1

我有一个使用pyramida / graphql的后端服务。后端正在端口4001上运行。这是我的Nginx配置文件proxy_pass:http://$host:4001]的代理通过

当我从服务器运行它时,它既可以在http://server:4001也可以在http://server上运行但是,当我从本地主机运行它时,出现以下错误:

no resolver defined to resolve localhost, client: 172.30.0.1, server: _, request: "GET / HTTP/1.1", host: "localhost"

什么原因导致此错误以及如何解决?

docker-compose:

backend:
    image: base
    command: >
      sh -c "npm run deploy && npm run start"
    env_file: ${ENV_FILE}
    ports:
      - '4001:4001'
    depends_on:
      - prisma
    restart: always
    volumes:
      - ./deploy/certs:/deploy/certs

  nginx:
    image: nginx:latest
    volumes:
      - ./deploy/certs:/deploy/certs
      - ./deploy/nginx/conf.d:/etc/nginx/conf.d
    ports:
      - 80:80/tcp
      - 443:443/tcp
    depends_on:
      - backend
    restart: always
    env_file: ${ENV_FILE}

nginx配置:

server {
    listen 80 default_server;
    server_name _;

location / {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://$host:4001;

  }
}

我有一个使用pyramida / graphql的后端服务。后端在端口4001上运行。这是我从服务器运行它时Nginx配置文件proxy_pass:http:// $ host:4001的代理服务器通道...

javascript nginx graphql prisma prisma-graphql
1个回答
0
投票

我想您需要连接到backend文件中docker-compose.yml中指定的nginx.conf服务。

© www.soinside.com 2019 - 2024. All rights reserved.