I have an independent Docker container just for nginx with “host” network mode, which should be able to directly communicate with any other containers running on the local machine.
I have a separate Docker container with an http service that is exposed on the same host via port 4500
, and I just want to be able to access it from my local network with a simple redirect, i.e. instead of curl http://192.168.1.8:4500
i want to do curl http://192.168.1.8/service
.
Below is my nginx.conf
:
events {}
http {
server {
listen 80;
location /service/ {
proxy_pass http://localhost:4500/;
}
}
}
and docker-compose.yaml
:
services:
nginx:
build: .
container_name: nginx
network_mode:
"host"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
And my Dockerfile:
FROM nginx:latest
COPY nginx.conf /etc/nginx/conf.d/default.conf
However, when I attempt to access http://192.168.1.8/service
I’m seeing this logged error when attempting to access http://localhost/service
, and a 502 Bad Gateway
client-side:
[error] 22#22: *1 connect() failed (111: Connection refused)
while connecting to upstream,
client: 192.168.1.8,
server: ,
request: "GET /service/ HTTP/1.1",
upstream: "http://192.168.1.8:50000/admin/",
host: "desktop.com"
I have no idea why it’s using port 50000
, it should be using port 4500
as I have in the nginx.conf. The upstream IP is correct, however.