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...