简体   繁体   English

nginx:[emerg] 在 /etc/nginx/nginx.conf:11 的上游“udagram-users:8080”中找不到主机

[英]nginx: [emerg] host not found in upstream "udagram-users:8080" in /etc/nginx/nginx.conf:11

After deploying to AWS EKS I get this error部署到AWS EKS后出现此错误

Gtihub repo: https://github.com/oussamabouchikhi/udagram-microservices Gtihub 仓库: https://github.com/oussamabouchikhi/udagram-microservices


Steps to reproduce重现步骤

  1. Create AWS EKS cluster and node groups创建AWS EKS集群和节点组
  2. Configure EKS cluster with kubectl使用kubectl配置EKS集群
  3. Deploy to EKS cluster (secrets first, then other services, then reverserproxy)部署到EKS集群(首先是 secrets,然后是其他服务,然后是 reverserproxy)
    . . kubectl apply -f env-secret.yaml
    . . kubectl apply -f aws-secret.yaml
    . . kubectl apply -f env-configmap.yaml
    . . ... ...
    . . kubectl apply -f reverseproxy-deployment.yaml
    . . kubectl apply -f reverseproxy-service.yaml

在此处输入图像描述

nginx-config nginx 配置

worker_processes 1;
  
events { worker_connections 1024; }
error_log /dev/stdout debug;

http {

    sendfile on;

    upstream users {
        server udagram-users:8080;
    }

    upstream feed {
        server udagram-feed:8080;
    }
    
    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-Forwarded-Host $server_name;
    
    server {
        listen 8080;
        location /api/v0/feed {
            resolver           8.8.8.8;
            proxy_pass         http://feed;
        }
        location /api/v0/users {
            resolver           8.8.8.8;
            proxy_pass         http://users;
        }            
    }

}

docker-compose docker-compose

version: '3'
services:
  reverseproxy:
    image: oussamabouchikhi/reverseproxy
    ports:
      - 8080:8080
    restart: always
    depends_on:
      - udagram-users
      - udagram-feed
    networks:
      - example-net
  udagram-users:
    image: oussamabouchikhi/udagram-api-users
    volumes:
      - $HOME/.aws:/root/.aws
    environment:
      POSTGRES_USERNAME: $POSTGRES_USERNAME
      POSTGRES_PASSWORD: $POSTGRES_PASSWORD
      POSTGRES_DB: $POSTGRES_DB
      POSTGRES_HOST: $POSTGRES_HOST
      AWS_REGION: $AWS_REGION
      AWS_PROFILE: $AWS_PROFILE
      AWS_MEDIA_BUCKET: $AWS_BUCKET
      JWT_SECRET: $JWT_SECRET
      URL: $URL
      networks:
        - example-net
  udagram-feed:
    image: oussamabouchikhi/udagram-api-feed
    volumes:
      - $HOME/.aws:/root/.aws
    environment:
      POSTGRES_USERNAME: $POSTGRES_USERNAME
      POSTGRES_PASSWORD: $POSTGRES_PASSWORD
      POSTGRES_DB: $POSTGRES_DB
      POSTGRES_HOST: $POSTGRES_HOST
      AWS_REGION: $AWS_REGION
      AWS_PROFILE: $AWS_PROFILE
      AWS_MEDIA_BUCKET: $AWS_BUCKET
      JWT_SECRET: $JWT_SECRET
      URL: $URL
    networks:
      - example-net
  udagram-frontend:
    image: oussamabouchikhi/udagram-frontend
    ports:
      - '8100:80'
    networks:
      - example-net
networks:
  example-net:
    external: true

reverseproxy-deployment反向代理部署

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    service: reverseproxy
  name: reverseproxy
spec:
  replicas: 1
  selector:
    matchLabels:
      service: reverseproxy
  template:
    metadata:
      labels:
        service: reverseproxy
    spec:
      containers:
        - image: oussamabouchikhi/reverseproxy:latest
          name: reverseproxy
          imagePullPolicy: Always
          resources:
            requests:
              memory: '64Mi'
              cpu: '250m'
            limits:
              memory: '1024Mi'
              cpu: '500m'
          ports:
            - containerPort: 8080
      restartPolicy: Always

reverseproxy-service反向代理服务

apiVersion: v1
kind: Service
metadata:
  labels:
    service: reverseproxy
  name: reverseproxy
spec:
  ports:
  - name: "8080"
    port: 8080
    targetPort: 8080
  selector:
    service: reverseproxy
  type: LoadBalancer

Use resolver in nginx confignginx配置中使用resolver

The nginx resolver directive is required.需要nginx resolver指令。

Nginx is a multiplexing server (many connections in one OS process), so each call of system resolver will stop processing all connections till the resolver answer is received. Nginx是一个多路复用服务器(一个OS进程中有很多连接),所以系统解析器的每次调用都会停止处理所有连接,直到收到解析器应答。 That's why Nginx implemented its own internal non-blocking resolver.这就是为什么 Nginx 实现了自己的内部非阻塞解析器。

If your config file has static DNS names (not generated), and you do not care about track IP changes without nginx reload , you don't need nginx 's resolver.如果您的配置文件有 static DNS名称(未生成),并且您不关心跟踪 IP 没有nginx reload的更改,则不需要nginx的解析器。 In this case all DNS names will be resolved on startup.在这种情况下,所有DNS名称都将在启动时解析。 Nginx 's resolver Nginx的解析器

Nginx resolver directive should be used, if you want to resolve domain name in runtime without nginx reload.如果要在运行时解析域名而无需nginx重新加载,则应使用Nginx resolver指令。

Eg:例如:

location /my_uri {
  resolver kube-dns.kube-system valid=10s;
  ...
}
location /my_uri {
  resolver 127.0.0.1:53 ipv6=off valid=10s;
  ...
}

Use the same.network (not your case, but still worth noting)使用 same.network (不是你的情况,但仍然值得注意)

Containers you are trying to link may not be on the same.network.您尝试链接的容器可能不在同一个网络上。 You may want to put them all on the same.network.你可能想把它们都放在同一个网络上。

In your case su.nets are the same, it's ok:在你的情况下 su.nets 是一样的,没关系:

docker-compose

version: '3'
services:
  reverseproxy:
    ...
    networks:
      - example-net
  udagram-users:
    ...
      networks:
        - example-net
  udagram-feed:
    ...
    networks:
      - example-net
  udagram-frontend:
    ...
    networks:
      - example-net
networks:
  example-net:
    external: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Elastic Beanstalk 上更改 nginx.conf? - Change nginx.conf on Elastic Beanstalk? NGINX docker-compose - 在上游 nuxt:3000 中找不到主机 - NGINX docker-compose - Host not found in upstream nuxt:3000 无法从 K8 集群编辑 nginx.conf 文件 - unable to edit nginx.conf file from K8 cluster 修改nginx.conf为Azure App Linux服务 - Modifying nginx.conf for Azure App Linux Service 连接到上游 nginx for aws 时 connect() 失败(113:主机无法访问) - connect() failed (113: Host is unreachable) while connecting to upstream nginx for aws 如何将 NGINX 设置为端口 8443、8444 和 8445 上游应用程序 8080 的反向代理 - How to setup NGINX as a reverse proxy on ports 8443, 8444, and 8445 to upstream app 8080 Nginx EKS 集群中的上游路由问题 - Nginx upstream routing issue in EKS cluster Upstream timed out error when deploying Docker Nginx FastAPI application on Google Cloud - Upstream timed out error when deploying Docker Nginx FastAPI application on Google Cloud AKS Ingress-Nginx ingress controller 主机路由失败 - AKS Ingress-Nginx ingress controller failing to route by host 在 AWS Elastic Beanstalk 上增加 Nginx conf 中的 client_max_body_size - Increasing client_max_body_size in Nginx conf on AWS Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM