Nginx Proxy Manager on Docker – Reverse Proxy

Nginx Proxy Manager on Docker – Reverse Proxy

In this tutorial, let’s learn how to set up nginx proxy manager on docker and a reverse proxy using it

What is a Reverse Proxy?

  • It is an intermediary proxy service which takes a client request, passes it on to one or more servers, and subsequently delivers the server’s response back to the client
  • 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
  • Furthermore, It provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers
Nginx

Benifits of setting up a Nginx Reverse Proxy

  • Load Balancing: It can perform load balancing which helps distribute client requests evenly across backend servers. It also improves redundancy as if one server goes down, the reverse proxy will simply reroute requests to a different server according to the routing policy.
  • Increased Security: It acts as a line of defense for your backend servers. Configuring a reverse proxy also ensures that the identity of your backend servers remains unknown.
  • Better Performance: Nginx performs better in delivering static content file and analyse URLs
  • Encrypted Connection: By encrypting the connection between the client and the Nginx reverse Proxy with TLS, users profit from a encrypted and secure HTTPS connection, which results in better protection of data.

Read more here:
https://www.nginx.com/resources/glossary/reverse-proxy-server/
https://nginxproxymanager.com/

For more docker tutorials and awesome stuff with docker refer: Docker Blogs

Pre-requesites

How to deploy Nginx Proxy Manager?

1. Create a folder to store all data from the docker container

# Create a folder and navigate into it
mkdir nginx
cd nginx

2. Create a docker-compose.yaml file for the configuration

The docker-compose file defines configurations for two services app and db. The properties can be modified according to your requirements. Using a secure username and password is recommended

nano docker-compose.yaml
# Add the below content into the file
version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
    environment:
      # These are the settings to access your db
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db
  db:
    image: 'jc21/mariadb-aria:latest'
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql

If you are running on a Raspberry Pi or any arm based system use the below for the docker-compose.yaml file

nano docker-compose.yaml
# Add the below content into the file
version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
    environment:
      # These are the settings to access your db
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "changeuser"
      DB_MYSQL_PASSWORD: "changepass"
      DB_MYSQL_NAME: "npm"
    volumes:
      - ./data/nginx-proxy-manager:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db
  db:
    image: yobasystems/alpine-mariadb:latest
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: "changeme"
      MYSQL_DATABASE: "npm"
      MYSQL_USER: "changeuser"
      MYSQL_PASSWORD: "changepass"
    volumes:
      - ./data/mariadb:/var/lib/mysql

3. Once this is done, deploy the services using the docker-compose command

# -d specifies to run in detached mode
docker-compose up -d

4. Once the containers are up, wait for about 2 mins for the containers to finish the configuration

Access the nginx proxy manager by browsing to http://<ip>:81

The default email is [email protected] and password is changeme

Nginx

5. Once signed in, you will be prompted to enter your details as shown below

Nginx

6. Once the details are enetered, you will be asked to change the default password

Nginx

7. Once this is done, you will be able to see the dashboard as shown below

Nginx

Congratulations!! You’ve deployed Nginx Proxy Manager on Docker successfully

How to setup a Reverse Proxy (Proxy Host) to expose a service on your server ?

1. On your dashboard, go to the Proxy Hosts section

Nginx

2. Click on Add Proxy Host to add an entry

In order to do add a reverse proxy, Enter the details as per your service and domain. In this case, we have used easycode.page as the domain and the requests to this domain will be forwarded to our service which is on 192.168.1.23:8080
Before setting this up, make sure that you have added an A record to your domain to point to the IP of your machine

3. Let us now setup SSL for this reverse proxy. Check the Force SSL option to force the all requests to use https

Nginx Proxy Manager uses Let’s Encrypt in order to generate a free SSL certificate for your domain

Click on save in order to generate an SSL certificate and save reverse your proxy settings

Nginx

Congratulations!! You’ve successfully setup a Reverse Proxy using Nginx Proxy Manager

3706cookie-checkNginx Proxy Manager on Docker – Reverse Proxy

4 Comments

  1. Pingback:PrivateBin - OpenSource PasteBin on Docker » EasyCode

  2. This website was… how do I say it? Relevant!!

    Finally I’ve found something that helped me. Kudos!

  3. Thanks – Enjoyed this blog post, how can I make is so that I receive an email whenever there is a fresh update?

  4. Wow, marvelous blog format! How lengthy have you been running a blog for?
    you made running a blog look easy. The overall look of your website is great, as well
    as the content material!

Leave a Comment

Your email address will not be published. Required fields are marked *