I try to run nginx in docker and connect it to one service in docker as well. Another service is running without docker and use this nginx too. My 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"
And nginx conf at ./config/nginx.conf:
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;
}
}
}
When I open localhost:9000 I get the error message:
lookup ws-web on 192.168.65.5:53: no such host
localhost:3000 works fine
What is my mistake?