Nginx Reverse Proxy for a Rails App with Docker

ADMAT Bandara
2 min readAug 1, 2019

--

Nginx is a web server. Check the following link for the official web site.

Mainly we can use this Nginx usefully as following ways.

  1. Reverse proxy
  2. Load balancer
  3. Main proxy
  4. HTTP cache

In this article I will be explaining how I used Nginx to deploy my Rails application.

If you are not using Docker, you can install Nginx into your machine locally, or in the server you maintain.

To install Nginx

apt-get install -y nginx

and the config files can be seen in the following directory

/etc/nginx/

Anyway…. I wanted to use these in Docker way.

Assume that the Rails application is already created and dockerized.

Next thing is to create the Nginx image.

I have created a Dockerfile with a config file to build my Nginx Image

Here is the Dockerfile

Config file for the Nginx. This example is about the Reverse Proxy

And that’s all I did to build my own Nginx file with a custom config file.

docker build -t admat/nginx:0.1 .

once the image is built I pushed the docker image to my Docker-hub account

docker push admat/nginx:0.1

Then, to have it with my Rails Application I added the image into my docker-compose file.

Here is the docker-compose file.

Finally , Up each containers one by one.

docker-compose up -d dbdocker-compose up -d rails-appdocker-compose up -d nginx

--

--