码头工人nginx ERR_NAME_NOT_RESOLVED [英] docker nginx ERR_NAME_NOT_RESOLVED

查看:130
本文介绍了码头工人nginx ERR_NAME_NOT_RESOLVED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行4个docker容器:服务器/客户端/nginx/mongo反向代理 客户端似乎在端口4200上工作,我可以看到我的应用程序和路由工作正常. 尝试注册用户时,我要求将以下httpclient帖子请求到名为"myserver"的Docker容器,该容器应调用api. 我收到此DNS错误消息.

Running 4 docker containers: server/client/nginx/mongo reverse-proxy The client seems to work on port 4200, I can see my app and routing works. When trying to register a user, I am requesting the below httpclient post to the Docker container called "myserver" which should call the api. I am getting this DNS error message.

在resolv.conf上查看NGINX容器时(它显示为127.0.0.11),这是正确的dns.Docker会在容器中解析dns-es. 当我从容器内ping到另一个容器的名称时,它可以工作. 当我从服务器端口3000上的容器的内部和外部进行telnet时,它与在客户端的端口4200上进行telneting一样有效 因此,当我尝试在我的网站上注册帐户时,可能无法解析myserver的原因是什么. 几乎好像是在容器外部进行了注册调用,因此它无法解决,这是正常现象吗?

When looking at the NGINX container at the resolv.conf (it shows 127.0.0.11) which is the correct dns Docker resolves the dns-es with within the container. When I ping from within the container to another container's name it works. when I telnet from within and outside of the container on the servers port 3000 it works as well as telnetting on client's port 4200 So what could be the cause of not being able to resolve myserver when I am trying to register an account on my website. it is almost as if the call to register is being made from outside the container, so it can't resolve it, is this normal behavior?

  let url = 'http://myserver:3000/api/register';

docker-compose.yml 版本:"3"

docker-compose.yml version: '3'

services:

  nginx:
      build: ./nginx
    # Map Nginx port 80 to the local machine's port 80
      volumes:
        - ./dist:/usr/share/nginx/html
      ports:
        - "80:80"
      depends_on: 
        - client
      networks:
        - app-network
   # Build the container using the client Dockerfile
  client:
      build: ./
    # This line maps the contents of the client folder into the container.
      volumes:
        - ./:/usr/src/app
      ports:
         - "4200:4200"
      networks:
        - app-network

  myserver:
      build: ./express-server
      volumes:
        - ./express-server:/usr/src/server
      environment:
        - NODE_ENV=development
      depends_on:
        - mongo
      ports:
        - "3000:3000"
      networks:
        - app-network

   # Link the client container so that Nginx will have access to it
  mongo:
      environment:
        - AUTH=yes
        - MONGO_INITDB_ROOT_USERNAME=superAdmin
        - MONGO_INITDB_ROOT_PASSWORD=admin123

      image: mongo
      volumes:
        - /var/mongodata/data:/data/db
      ports:
        - "27017:27017"
      networks:
        - app-network   

networks:
   app-network:
      driver: bridge

nginx default.conf

nginx default.conf

worker_processes 2 ;

events {
    worker_connections 1024;
}
http {
    upstream my-server {
    server myserver:3000;
    }

    upstream client {
    server client:4200;
    }

    server {
        
        location / {
            proxy_pass http://client;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header X-Forwarded-For $remote_addr;
        }
        location /api/ {
            proxy_pass http://my-server;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header X-Forwarded-For $remote_addr;
    }        
    }
}

cbdb2e00c6db        meanchat_nginx      "nginx -g 'daemon ..."   15 minutes ago      Up 15 minutes       0.0.0.0:80->80/tcp         meanchat_nginx_1
22406a1e9a31        meanchat_client     "npm start"              15 minutes ago      Up 15 minutes       0.0.0.0:4200->4200/tcp     meanchat_client_1
aa024855d201        meanchat_myserver   "npm start"              About an hour ago   Up 15 minutes       0.0.0.0:3000->3000/tcp     meanchat_myserver_1
b657bd6db7b5        mongo               "docker-entrypoint..."   5 hours ago         Up 15 minutes       0.0.0.0:27017->27017/tcp   b657bd6db7b5_meanchat_mongo_1

172.20.0.1 - - [09/Jan/2018:00:30:02 +0000] "GET /sockjs-node/info?t=1515457802565 HTTP/1.1" 200 90 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:03 +0000] "GET /register HTTP/1.1" 304 0 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:03 +0000] "GET /sockjs-node/044/zh1t2skg/websocket HTTP/1.1" 101 162 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"172.20.0.1 - - [09/Jan/2018:00:30:03 +0000] "GET /inline.bundle.js HTTP/1.1" 304 0 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:03 +0000] "GET /polyfills.bundle.js HTTP/1.1" 304 0 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:03 +0000] "GET /vendor.bundle.js HTTP/1.1" 304 0 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:03 +0000] "GET /styles.bundle.js HTTP/1.1" 304 0 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:03 +0000] "GET /scripts.bundle.js HTTP/1.1" 304 0 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:03 +0000] "GET /main.bundle.js HTTP/1.1" 200 796563 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:06 +0000] "GET /assets/img/cryptoowls.jpg HTTP/1.1" 304 0 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:06 +0000] "GET /roboto-v15-latin-regular.7e367be02cd17a96d513.woff2 HTTP/1.1" 304 0 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
172.20.0.1 - - [09/Jan/2018:00:30:06 +0000] "GET /sockjs-node/info?t=1515457806564 HTTP/1.1" 200 90 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"

172.20.0.1--[09/一月/2018:03:31:24 +0000]"GET/sockjs-node/info?t = 1515468684563 HTTP/1.1" 200 90"

172.20.0.1 - - [09/Jan/2018:03:31:24 +0000] "GET /sockjs-node/info?t=1515468684563 HTTP/1.1" 200 90 "http://localhost/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"

推荐答案

评论的答案:

使用反向代理连接到容器时,应用程序使用的所有URL都必须指向该反向代理,而不是应用程序.通常,您可以通过在URL中提供不带主机名的路径来实现.如果您打算使用基于虚拟路径的反向代理,则需要更进一步,并在URL中使用相对路径.这一切都需要在应用程序发送给客户端的响应中发生.

When connecting to containers with a reverse proxy, all the URL's used by the application need to point to that reverse proxy and not the application. Typically you do this by giving a path in the URL without a hostname. If you plan to use a virtual path based reverse proxy, you'll want to go a step further and use relative paths in your URL's. This all needs to happen in the responses being sent by the application to the client.

这篇关于码头工人nginx ERR_NAME_NOT_RESOLVED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆