当网络中的容器更改其 IP 时,我遇到了 nginx 问题,我可以在 Linux 操作系统中访问它,但 nginx 无法解析新 IP...我搜索了很多解决方案,我发现 nginx 告诉我们使用解析器指令,然后我尝试了它但没有任何变化....无法使这个解析器工作,有什么我应该检查的吗?我什么都试过了....
西蒙尼能帮我提供一些提示吗?
注意:我正在使用 ecs fargate。
先谢谢了。
docker-compose.yml:
version: "3.7"
x-aws-loadbalancer: ***
services:
i***-root:
image: ***
container_name: i***-root
ports:
- "80:80"
- "443:443"
depends_on:
- i***-angular
- i***-react
i***-angular:
image: ***
container_name: i***-angular
i***-react:
image: ***
container_name: i***-react
x-aws-cloudformation:
Resources:
I***angularService:
Properties:
EnableExecuteCommand: true
I***reactService:
Properties:
EnableExecuteCommand: true
I***rootService:
Properties:
EnableExecuteCommand: true
I***angularTaskDefinition:
Properties:
Cpu: 2048
Memory: 4096
TaskRoleArn: ***
I***reactTaskDefinition:
Properties:
Cpu: 2048
Memory: 4096
TaskRoleArn: ***
I***rootTaskDefinition:
Properties:
Cpu: 2048
Memory: 4096
TaskRoleArn: ***
I***rootTCP80TargetGroup:
Properties:
HealthCheckPath: /
I***rootTCP443TargetGroup:
Properties:
Protocol: HTTPS
HealthCheckPath: /
I***rootTCP443Listener:
Properties:
Protocol: HTTPS
Certificates:
- CertificateArn: ***
Dockerfile 的“i*-根”:**
FROM node:16 as build-root
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY map.json ./
COPY package.json yarn.lock ./
RUN yarn install
COPY . .
RUN yarn build
COPY ./public /app/dist/
FROM nginx:alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx-custom.conf /etc/nginx/conf.d/nginx-custom.conf
COPY nginx/nginx-custom443.conf /etc/nginx/conf.d/nginx-custom443.conf
COPY nginx/***-cert.pem /etc/ssl/certs/***-cert.pem
COPY nginx/***-private.pem /etc/ssl/certs/***-private.pem
WORKDIR /usr/share/nginx/html
COPY --from=build-root /app/dist .
CMD ["nginx", "-g", "daemon off;"]
nginx-custom.conf(我尝试在其中应用解析器解决方案)
server {
listen 80 default_server;
server_name default;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
resolver 172.16.0.23 ipv6=off valid=10s;
set $upstream_endpoint http://***-react;
location /***-react/ {
rewrite ^/***-react/(.*) /$1 break;
proxy_pass $upstream_endpoint;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_set_header IdRef $http_IdRef;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
fastcgi_read_timeout 999999;
proxy_connect_timeout 999999;
proxy_send_timeout 999999;
proxy_read_timeout 999999;
send_timeout 999999;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
}
但是我之前是怎么说的呢,这个解析器指令改变了一切......看起来 nginx 一直在缓存 dns,我试过使用 google dns 8.8.8.8 或 /etc/resolve.conf 名称服务器,但一切正常......我有点困惑。
我按照 nginx 文档操作,其中说解析器指令应该可以解决这个问题。
答案1
我会用这个
https://github.com/nginx-proxy/nginx-proxy/tree/main/docs
version: '2'
services:
nginx-proxy:
image: nginxproxy/nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
whoami:
image: jwilder/whoami
expose:
- "8000"
environment:
- VIRTUAL_HOST=whoami.example
- VIRTUAL_PORT=8000