gpt4 book ai didi

docker nginx ERR_NAME_NOT_RESOLVED

转载 作者:行者123 更新时间:2023-12-02 18:30:27 25 4
gpt4 key购买 nike

运行 4 个 docker 容器:server/client/nginx/mongo reverse-proxy客户端似乎在端口 4200 上工作,我可以看到我的应用程序和路由工作。尝试注册用户时,我请求将下面的 httpclient post 发送到名为“myserver”的 Docker 容器,它应该调用 api。我收到此 DNS 错误消息。

当在 resolv.conf(它显示 127.0.0.11)中查看 NGINX 容器时,这是正确的 dns Docker 在容器内解析 dns-es。当我从容器内 ping 到另一个容器的名称时,它起作用了。当我从服务器端口 3000 上的容器内部和外部远程登录时,它的工作原理与客户端端口 4200 上的远程登录一样好那么当我尝试在我的网站上注册帐户时无法解析 myserver 的原因可能是什么。就好像注册调用是从容器外部发出的,所以它无法解析它,这是正常行为吗?

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

docker-compose.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 默认.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/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"

最佳答案

来自评论的回答:

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

关于docker nginx ERR_NAME_NOT_RESOLVED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48160019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com