NGINX Reverse Proxy for Docker

This post is a guide on setting the NGINX Config to work as a reverse proxy to our web application inside a docker container. When you use docker to host your web applications and services. It's handy to be able to use a reverse proxy to pass the traffic on port 80 and route it to the right container.

One cool thing about NGINX is we can running docker and static sites on the same linux box. It's just a case of having different NGINX config files.

I've setup a web application built in .net core and running inside a container. On my linux server I create a docker instance and set it to run on port 8080.

docker run --name some-app1 -d -p 8080:80 some-app1

Once the docker container is running we can go ahead and create a NGINX config for the reverse proxy.

Reverse Proxy Config

First in the folder we need to create our config.

/etc/nginx/site-available

The following is our reverse proxy config for a website I have called 'touroperator.io'

server {
  listen 80;

  listen [::]:80;

  server_name touroperator.io www.touroperator.io;

   set $upstream 127.0.0.1:8080;

 location / {
 
 proxy_pass_header Authorization;
 proxy_pass http://$upstream;
 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_http_version 1.1;
 proxy_set_header Connection "";
 proxy_buffering off;
 client_max_body_size 0;
 proxy_read_timeout 36000s;
 proxy_redirect off;
 }
}

The config is doing a number of things.

  • Listen for traffic on Port 80
  • Only deal with requests for the touroperator.io or www.touroperator.io domain name
  • Upstream we set it to 127.0.0.1 and port 8080 so it's sending traffic to it's own network card on port 8080. This is the same port our docker image is running on.
  • Next in Location we pass a number of bits of information up the pipe to the website.

Note: this type of config can be used for load balancing and other things. As I explore this deeper more posts will follow.

Next we need to create a short cut in the 'site-enabled' folder.

ln -s /etc/nginx/sites-available/touroperator.io /etc/nginx/sites-enabled/touroperator.io

Remember to change the file name to your own.

Lastly reload the NGINX server

nginx -s reload

And point your DNS and you are running. The traffic will be routed to the docker container.

This post is a guide on setting the NGINX Config to work as a reverse proxy to our web application inside a docker container. When you use docker to host your web applications and services. It's handy to be able to use a reverse proxy to pass the traffic on…

Read More

Setting up Docker on Linode

A quick guide to setting up Docker on a Linode Ubuntu server. As I go deeper into exploring docker and building applications and services in new ways, I wanted a post that acts as a starting point.

Installing docker

$ sudo apt-get update

First, add the GPG key for the official Docker repository to the system:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to APT sources:

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Then Install Docker

sudo apt-get install -y docker-ce

Check the Docker Status

sudo systemctl status docker

That's it docker is now running on our Linux server. I will be adding more posts to the blog as I explore docker more.

A quick guide to setting up Docker on a Linode Ubuntu server. As I go deeper into exploring docker and building applications and services in new ways, I wanted a post that acts as a starting point. Installing docker $ sudo apt-get update First, add the GPG key for the official…

Read More

Docker Explained

Docker
What is docker

Docker containers wrap up a piece of software in a complete file system that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.

When you develop with docker development, test and production can all have the same container. Which means if it works for development it will work in production. Makes it easy to update, test and change.

Docker runs on the linux kernal which means it can not run windows inside a container but you can get Docker to run on a windows server with either virtual box or HyperV

Docker VS virtual machines

Docker looks like a virtual machine but it isn't a virtual machine. With Docker think in terms of PAAS.

Virtual machines have a full OS with its own memory management installed with the associated overhead of virtual device drivers. In a virtual machine, valuable resources are emulated for the guest OS and hypervisor, which makes it possible to run many instances of one or more operating systems in parallel on a single machine (or host). Every guest OS runs as an individual entity from the host system.

On the other hand Docker containers are executed with the Docker engine rather than the hypervisor. Containers are therefore smaller than Virtual Machines and enable faster start up with better performance, less isolation and greater compatibility possible due to sharing of the host’s kernel.

More information

For Windows or MAC or Linux under install find your flavour.

You can also run Docker on the cloud

Docker What is docker Docker containers wrap up a piece of software in a complete file system that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment…

Read More