DEV Community

Ali Zulfaqar
Ali Zulfaqar

Posted on

2 2

Run multiple services with nginx reverse proxy

Requirement

  • docker desktop
  • basic knowledge of how docker works

Getting Started

What is nginx reverse proxy ?

  • nginx reverse proxy can be simplified as client is accessing the site via nginx acting as the middleware between client and site

What is the benefit ?

  • you can have multiple site under 1 nginx middleware

How to get started ?

  • Create a new docker-compose.yml file
  • Content of the docker-compose.yml
version: '3.7'

services:

  proxy:
    image: jwilder/nginx-proxy
    container_name: proxy-test
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

  container1:
    image: httpd:2.4
    container_name: container-1
    environment:
      - VIRTUAL_HOST:container1.com
    ports:
      - 8080:80

  container2:
    image: httpd:2.4
    container_name: container-2
    environment:
      - VIRTUAL_HOST:container2.com
    ports:
      - 8081:80
Enter fullscreen mode Exit fullscreen mode
  • after you have filled in the docker-compose.yml with the code above, save and run the file by using command

docker-compose up -d

  • You can access the container by opening localhost:<port>, for this example it is running on localhost:8080 and localhost:8081

Conclusion

  • As my writing has reached it's end, i would like to say thank you for reading this article and have a try playing around with nginx reverse proxy, maybe it will give you more ideas on how to manage your site deployment

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started