🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Serving MDriven with Nginx Server as a Proxy
Created by Stephanie on 2024-12-20 · Last edited by Peter.byaruhanga on 2026-07-23.

Serving MDriven with Nginx Server as a Proxy

This article continues from the MDriven local installation guide.

Before configuring Nginx as a reverse proxy, complete the MDriven Server and MDriven Turnkey installation using:

HowTos: Local Installation

After successfully installing MDriven on the Ubuntu Server, the installation also ensures that the Nginx web server is installed.

MDriven Server and MDriven Turnkey should already be running on the following internal ports:

  • MDriven Server: 5010
  • MDriven Turnkey: 5011

Nginx will act as a reverse proxy and forward incoming requests to the appropriate MDriven service.

Check the Nginx Service

Check the status of the Nginx service using the following command:

service nginx status

For newer Linux systems, use:

sudo systemctl status nginx

The result should show:

Active: active (running)

This indicates that the Nginx service is running.

If Nginx is not running, start it using:

sudo service nginx start

For newer Linux systems, use:

sudo systemctl start nginx

You should also confirm that MDriven Server and MDriven Turnkey are running:

sudo systemctl status mdrivenserver.service
sudo systemctl status mdriventurnkey.service

You can test the applications directly from the server using:

curl http://127.0.0.1:5010
curl http://127.0.0.1:5011

Step -1: Configure Nginx

Navigate to the Nginx directory where the configuration files for MDriven Server and MDriven Turnkey will be created:

cd /etc/nginx/sites-available

The /etc/nginx/sites-available directory contains configuration files for Nginx virtual hosts.

Each file in this directory represents a separate website or application hosted through Nginx.

A default configuration file may already exist. You can leave it in place or disable it if it conflicts with the MDriven configurations.

To disable the default site, use:

sudo rm /etc/nginx/sites-enabled/default

Step -2: Create a Configuration File for MDriven Server

Create the MDriven Server Nginx configuration file:

sudo nano /etc/nginx/sites-available/mdrivenserver

Copy and paste the following content into the file.

Replace server.example.com with the domain name pointing to your Ubuntu server.

server {
    listen 80;
    server_name server.example.com;

    location / {
        proxy_pass http://127.0.0.1:5010;
        proxy_http_version 1.1;

        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_set_header X-Forwarded-Proto $scheme;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_read_timeout 300;
        proxy_connect_timeout 300;
        proxy_send_timeout 300;

        proxy_redirect off;
    }

    error_log /var/log/nginx/mdriven_server_error.log;
    access_log /var/log/nginx/mdriven_server_access.log;
}

This configuration forwards requests received through:

http://server.example.com

to the MDriven Server application running internally on:

http://127.0.0.1:5010

Save the file by pressing Ctrl+O, press Enter, and then exit Nano by pressing Ctrl+X.

Step -3: Create a Configuration File for MDriven Turnkey

Create the MDriven Turnkey Nginx configuration file:

sudo nano /etc/nginx/sites-available/mdriventurnkey

Copy and paste the following content into the file.

Replace turnkey.example.com with the domain name pointing to your Ubuntu server.

server {
    listen 80;
    server_name turnkey.example.com;

    location / {
        proxy_pass http://127.0.0.1:5011;
        proxy_http_version 1.1;

        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_set_header X-Forwarded-Proto $scheme;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_read_timeout 300;
        proxy_connect_timeout 300;
        proxy_send_timeout 300;

        proxy_redirect off;
    }

    error_log /var/log/nginx/mdriven_turnkey_error.log;
    access_log /var/log/nginx/mdriven_turnkey_access.log;
}

This configuration forwards requests received through:

http://turnkey.example.com

to the MDriven Turnkey application running internally on:

http://127.0.0.1:5011

Save the file by pressing Ctrl+O, press Enter, and then exit Nano by pressing Ctrl+X.

Step -4: Enable the MDriven Sites

Create symbolic links for both configuration files in the Nginx sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/mdrivenserver /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/mdriventurnkey /etc/nginx/sites-enabled/

Test the Nginx configuration:

sudo nginx -t

A successful result should show:

syntax is ok
test is successful

Restart Nginx to apply the configuration:

sudo service nginx restart

For newer Linux systems, use:

sudo systemctl restart nginx

Check that Nginx restarted successfully:

sudo systemctl status nginx

Step -5: Configure the Firewall

Allow HTTP and HTTPS traffic through Nginx:

sudo ufw allow 'Nginx Full'

Check the firewall status:

sudo ufw status

When Nginx is being used as the public entry point, ports 5010 and 5011 normally do not need to remain publicly accessible.

Nginx communicates with these services locally through:

127.0.0.1:5010
127.0.0.1:5011

If public firewall rules were previously created for these ports, they can be removed:

sudo ufw delete allow 5010/tcp
sudo ufw delete allow 5011/tcp

Only remove these rules after confirming that Nginx is correctly forwarding requests.

Step -6: Access MDriven Over HTTP

You can now access MDriven Server using:

http://server.example.com

You can access MDriven Turnkey using:

http://turnkey.example.com

Replace the example domains with the actual domains configured in the Nginx files.

Both domain names must have DNS records pointing to the public IP address of the Ubuntu server.

Step -7: Install Certbot and the Nginx Plugin

The MDriven Server and MDriven Turnkey applications are currently accessible through HTTP.

For a production installation, HTTPS should be enabled using Certbot and Let's Encrypt.

Update the package list:

sudo apt update

Install Certbot and the Nginx plugin:

sudo apt install certbot python3-certbot-nginx

Step -8: Ensure Nginx Is Running

Start Nginx if it is not already running:

sudo service nginx start

For newer Linux systems, use:

sudo systemctl start nginx

Check its status:

sudo systemctl status nginx

Step -9: Obtain SSL Certificates

Before requesting certificates, ensure that:

  • Both domain names point to the Ubuntu server.
  • Ports 80 and 443 are open.
  • The Nginx configuration test is successful.
  • Both domains are accessible over HTTP.

Run Certbot for both MDriven domains:

sudo certbot --nginx -d server.example.com -d turnkey.example.com

Replace the example domains with your actual domain names.

Follow the prompts displayed by Certbot.

Certbot will:

  • Request the SSL certificates.
  • Update the Nginx configuration.
  • Configure HTTPS.
  • Offer to redirect HTTP traffic to HTTPS.

Select the option to redirect HTTP traffic to HTTPS when prompted.

Let's Encrypt generally requires valid public domain names. A private or local IP address such as 10.0.2.15 cannot normally be used to obtain a public Let's Encrypt certificate.

Step -10: Verify the HTTPS Configuration

Test the updated Nginx configuration:

sudo nginx -t

Restart Nginx:

sudo service nginx restart

For newer Linux systems, use:

sudo systemctl restart nginx

You should now be able to access MDriven Server using:

https://server.example.com

You should be able to access MDriven Turnkey using:

https://turnkey.example.com

Step -11: Verify Automatic Certificate Renewal

Let's Encrypt certificates are valid for 90 days.

Certbot normally installs a systemd timer that automatically checks for certificate renewal.

Check the Certbot renewal timer:

sudo systemctl status certbot.timer

Test the renewal process:

sudo certbot renew --dry-run

If the test completes successfully, automatic renewal is configured correctly.

Troubleshooting

Test the Nginx Configuration

sudo nginx -t

Check the Nginx Service

sudo service nginx status

For newer Linux systems:

sudo systemctl status nginx

Check MDriven Server

sudo systemctl status mdrivenserver.service

Check MDriven Turnkey

sudo systemctl status mdriventurnkey.service

Test MDriven Server Locally

curl http://127.0.0.1:5010

Test MDriven Turnkey Locally

curl http://127.0.0.1:5011

If the local commands fail, the issue is likely with the MDriven service rather than Nginx.

Check the Nginx Journal

sudo journalctl -u nginx -n 100 --no-pager

View the MDriven Server Nginx Error Log

sudo tail -f /var/log/nginx/mdriven_server_error.log

View the MDriven Turnkey Nginx Error Log

sudo tail -f /var/log/nginx/mdriven_turnkey_error.log

Restart All Services

sudo systemctl restart mdrivenserver.service
sudo systemctl restart mdriventurnkey.service
sudo systemctl restart nginx

After completing these steps, MDriven Server and MDriven Turnkey will be available through Nginx using standard HTTP and HTTPS ports.