Setting up NGINX inside Docker to proxy host applications
Fortunately for us, Docker is built with inherent support for container-to-host connections. When setting up NGINX inside a container, a special host.docker.internal
hostname is used to target the host machine.
Here’s a sample NGINX proxy configuration for interfacing with a web application hosted on the server:
server { listen 80; location /hostapp { proxy_pass http://host.docker.internal:4000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
To ensure NGINX can communicate with...