我尝试在 docker 中运行 nginx 并将其连接到 docker 中的一项服务。另一个服务在没有 docker 的情况下运行,也使用这个 nginx。我的 docker-compose:
version: "3.9"
services:
nginx:
restart: always
image: nginx
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "3000:80"
- "9000:81"
web:
restart: always
image: "xxxx/xxxx/web"
和 ./config/nginx.conf
处的 nginx 配置:
events {}
http{
upstream ws-api {
server host.docker.internal:8081;
}
upstream ws-web {
server web;
}
server {
server_name localhost;
listen 80;
location / {
include fastcgi_params;
fastcgi_split_path_info ^(/)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_pass ws-api;
}
}
server {
server_name localhost;
listen 81;
location / {
include fastcgi_params;
proxy_pass http://ws-web;
}
location /api {
rewrite ^([^.]*[^/])$ $1/;
rewrite ^/api(.*)$ $1 break;
include fastcgi_params;
fastcgi_split_path_info ^(/)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_pass ws-api;
}
}
}
当我打开 localhost:9000 时,我收到错误消息:
<块引用>在 192.168.65.5:53 上查找 ws-web:没有这样的主机
localhost:3000 工作正常
我的错误是什么?