当前位置: 首页 > 知识库问答 >
问题:

docker nginx错误\u名称\u未\u解析

谯嘉胜
2023-03-14

运行4 docker容器:服务器/客户端/nginx/mongo反向代理客户端似乎在端口4200上工作,我可以看到我的应用程序和路由工作。当尝试注册用户时,我请求下面的http客户端帖子到名为“myserver”的Docker容器,该容器应该调用api。我得到这个DNS错误消息

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

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

docker撰写。yml版本:“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默认值。形态

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/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,类似Gecko)Chrome/63.0.3239.132 Safari/537.36”

共有1个答案

严稳
2023-03-14

评论的答复:

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

 类似资料:
  • 目前我收到了这种信息,我不知道如何修复它。 命令告诉我PDO和PDO_mysql就在那里。 我将Drupal-8与php7一起使用。Ubuntu 18.04上的1.20。1 LTS [Tue Sep04 09:27:48.210064 2018][php7:通知][pid 2183][客户端10.56.99.1:53758]错误:未定义的类常量'MYSQL_ATTR_USE_BUFFERED_QU

  • 在Laravel-5.8项目中,从这个控制器: 我航行到: 使用: 当我想导航回: 公共功能manager_employee_goal($id) 我用过: 但我有一个错误: 路径[evaluation.evaluation\u goals.manager\u employee\u goal/{id?}]未定义 以下是我的路线/web.php: 我如何解决它? 谢谢你

  • 我目前正在尝试编译和测试一个小型Android应用程序。 我正在使用Eclipse,并安装了SDK 4.2(Api级别17)。我准备好了 虽然我也尝试了不同的值(即17/17)。 我不使用任何GoogleAPI函数,也不使用API Level 8中不可用的函数。或者至少我在这方面没有收到任何编译错误或警告。 当我编译项目并在运行Android 2.2.1的真实设备上运行时,应用程序运行良好。但是,

  • 使用win10 64位 当我试图通过

  • 我正在开发一个应用程序,用于连接基于HFP(BluetoothHeadset)协议的蓝牙设备。 蓝牙耳机通过蓝牙HFP发送AT(ACTION\u VENDOR\u SPECIFIC\u headset\u EVENT)指令。我已经成功地建立了设备之间的连接。 我已经写了一个广播接收器,并在舱单上登记了它。 上述接收器适用于广播中提及的所有动作和触发器,但 “android.bluetooth.he

  • 当我尝试将Woocommerce插件更新到新版本(3.6.1)时,我遇到了这个错误 [2019年4月21日20:29:10 UTC]PHP致命错误:未捕获错误:调用未定义函数作为下一个\u计划的\u操作()在 /home/tleelxvn/fairo.pk/wp- 内容/plugins/woocommerce/includes/queue/class wc action queue.php:127