Table of Contents

Mesh Central in Docker behind NGINX Proxy Manager Reverse Proxy

Prerequisites

  1. Docker environment on Linux
  2. Portainer, docker-compose installed
  3. Ports 80/443 port forwarded to your Docker host
  4. Reverse proxy being Nginx Proxy Manager, not Traefik as I don't use it
  5. Nginx Proxy Manager listening for ports 80/443

Deploying container

version: '3'

networks:
  reverse_proxy:
    external: true
volumes:
  data:
  files:
    
services:
    mongodb:
        container_name: meshcentral_db
        restart: always
        image: mongo:latest
        expose:
            - 27017
        volumes:
            - '/docker/containers/meshcentral/database:/data/db'
        networks:
          - reverse_proxy
          
    meshcentral:
        restart: always
        container_name: meshcentral
        depends_on:
            - 'mongodb'
        image: typhonragewind/meshcentral:mongodb-latest
        ports:
            - 8786:443 #MeshCentral will moan and try everything not to use port 80, but you can also use it if you so desire, just change the config.json according to your needs
        environment:
            - HOSTNAME=meshcentral.laptopwiki.eu     #your hostname
            - REVERSE_PROXY=nginx-proxy-manager     #set to your reverse proxy IP if you want to put meshcentral behind a reverse proxy
            - REVERSE_PROXY_TLS_PORT=443 #internal https port, only change if you don't use 443 for your incoming HTTPS for some reason
            - IFRAME=false #set to true if you wish to enable iframe support
            - ALLOW_NEW_ACCOUNTS=false    #set to false if you want disable self-service creation of new accounts besides the first (admin)
            - WEBRTC=false  #set to true to enable WebRTC - per documentation it is not offically released with meshcentral, but is solid enough to work with. Use with caution
            - NODE_ENV=production
            - TZ=Europe/Prague
        volumes:
            - data:/opt/meshcentral/meshcentral-data
            - files:/opt/meshcentral/meshcentral-files
        networks:
          - reverse_proxy

Config File

{
  "$schema": "http://info.meshcentral.com/downloads/meshcentral-config-schema.json",
  "settings": {
    "cert": "meshcentral.laptopwiki.eu",
    "_WANonly": true,
    "_LANonly": true,
    "_sessionKey": "generate_password_here", 
    "port": 443,
    "_aliasPort": 443,
    "redirPort": 80,
    "_redirAliasPort": 80,
    "AgentPong": 300,
    "TLSOffload": "nginx-proxy-manager",
    "_ignoreAgentHashCheck": false,
    "SelfUpdate": false,
    "AllowFraming": "false",
    "mongodb": "mongodb://mongodb:27017/mesh",
    "mongodbcol": "mesh",
    "WebRTC": "false"
  },
  "domains": {
        "": {
          "_title": "Mesh Central",
          "_title2": "Mesh Central",
          "_minify": true,
          "NewAccounts": "false",
          "_userNameIsEmail": true,
          "certUrl": "https://meshcentral.laptopwiki.eu:443"
        }
  },
  "_letsencrypt": {
    "__comment__": "Requires NodeJS 8.x or better, Go to https://letsdebug.net/ first before>",
    "_email": "[email protected]",
    "_names": "myserver.mydomain.com",
        "production": false
  }
}

So what are we changing and why?

  1. “cert”: “meshcentral.laptopwiki.eu” - to tell Mesh Central what certificate to use - works even if you use a wildcard certificate (*.laptopwiki.eu)
  2. “_sessionKey”: “generate_password_here”, - please use a password manager to generate a random password here
  3. “TLSOffload”: “nginx-proxy-manager” - set Docker hostname or IP address of your NPM installation, don't put port here
  4. “port”: 443, - change if you don't use 443. If your NPM isn't on the same docker host this should be the exposed port (for example 8786) but I haven't tested it so I don't really know.
  5. “certUrl”: “https://meshcentral.laptopwiki.eu:443” - Public FQDN of your Mesh Central server, including the port

NGINX Proxy Manager

  1. Add a new Proxy host as you would with any other Docker container
  2. Don't forget to check Websockets Support
  3. In SSL select your certificate, force SSL and enable HTTP/2
  4. In the Advanced tab paste the following
proxy_set_header CF-Connecting-IP $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

If Cloudflare Proxy

  1. This setup works fine through Cloudflare Proxy, assuming
  2. Cloudflare Dashboard → yourdomain.tld → SSL/TLS → Overview → FULL
  3. This is necessary so that the Cloudflare Proxy and your local certificate match and Cloudflare doesn't try to redirect

Issues

Unable to connect web socket

  1. If you get this error after logging into the Mesh Central WebUI do:
  2. Go to NPM
  3. In Proxy Host → your Mesh Central Host → Check Websockets Support

dustojnikhummer 30/07/2023 00:11