Nginx Reverse Proxy for a Rails App with Docker

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

--

--

--

Developer ❤️ JS

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ADMAT Bandara

ADMAT Bandara

Developer ❤️ JS

More from Medium

How to Design a Better Command Line Interface

Mad World — accessing resources behind a VPN from within a docker container

Creating Rails Api Using Existing MySql Database

Swapping Elasticsearch for Meilisearch in Rails feat. Docker