Short description:
Nginx running on docker, how to configure nginx so that it forwards calls to host.
Long description:
We have one web application which communicates to couple of backends (lets says rest1, rest2 and rest3). We are responsible for rest1
.
Lets consider that I started rest1
manually on my pc and running on 2345 port. I want nginx (which is running in docker) to redirect all call torest1
to my own running instance(note, the instance is running on host, not any container and not in docker). And for rest2
and rest3
to some other docker node or may be some other server (who cares).
What I am looking for is:
docker-compose.yml
configurations (if needed).Thanks in advance.
In Docker 17.07 and higher, you can configure the Docker client to pass proxy information to containers automatically. In Docker 17.06 and earlier versions, you must set the appropriate environment variables within the container.
A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.
The Nginx proxy manager (NPM) is a reverse proxy management system running on Docker. NPM is based on an Nginx server and provides users with a clean, efficient, and beautiful web interface for easier management.
Configure nginx like the following (make sure you replace IP of Docker Host) and save it as default.conf
:
server { listen 80; server_name _; location / { proxy_pass http://<IP of Docker Host>; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
Now bring up the container:
docker run -d --name nginx -p 80:80 -v /path/to/nginx/config/default.conf:/etc/nginx/conf.d/default.conf nginx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With