【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
场景是这样的:
在docker容器中nginx下部署了两个项目,分别为a.com和b.com.
nginx配置文件部分如下:
location ~ \.php(.*)$ {
root /var/www/html/ad-api/api/src/public/;
fastcgi_pass myphp:9000;
fastcgi_index index.php;
}
然后我在a.com项目中需要curl b.com中的接口,会报如下错误:Failed to connect to b.com port 80: Connection refused
我的解决方式是在php-fpm容器内绑定了nginx容器的host: nginx容器ip:b.com
但由于容器的ip是变化的,所以想请问有没有其他更好的解决方式。
docker-compose.yml
version: '3'
services:
myphp:
build: ./php
container_name: myphp
extra_hosts:
- "b.com: nginx容器ip" //这里还没有nginx的ip,应该怎么写啊
network_mode: my-bridge
ports:
- "9000:9000"
volumes:
- /Users/aa/learn/html:/var/www/html
- /Users/aa/learn/php:/usr/local/etc/php
nginx0717:
image: nginx:latest
container_name: nginx0717
ports:
- "80:80"
- "443:443"
network_mode: my-bridge
volumes:
- /Users/aa/learn/html:/usr/share/nginx/html
- /Users/aa/learn/nginx:/etc/nginx