Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker nginx proxy to host

Tags:

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:

  1. docker-compose.yml configurations (if needed).
  2. nginx configuration.

Thanks in advance.

like image 945
Jahid Shohel Avatar asked Feb 24 '17 12:02

Jahid Shohel


People also ask

Does Docker use system proxy?

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.

How does nginx reverse proxy work?

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.

What is nginx proxy manager?

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.


1 Answers

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 
like image 126
Farhad Farahi Avatar answered Sep 25 '22 17:09

Farhad Farahi