Domain Setup
This guide walks you through pointing a custom domain to your MJ Bot dashboard using nginx as a reverse proxy and Certbot for free SSL certificates.
Prerequisites
- A registered domain name
- DNS A record pointing your domain to your server's IP address
- The dashboard running on port 3000 (see Dashboard Setup)
Install Nginx
Install nginx on your server:
apt install nginx
Verify that nginx is running:
systemctl status nginx
Create the Nginx Configuration
Create a new configuration file for your domain:
nano /etc/nginx/sites-available/your-domain
Paste the following configuration, replacing your-domain.com with your actual domain:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_cache_bypass $http_upgrade;
}
}
The Upgrade and Connection headers are included to support WebSocket connections, which Next.js uses for hot reloading in development and for certain real-time features.
Enable the Site
Create a symbolic link to enable the configuration:
ln -s /etc/nginx/sites-available/your-domain /etc/nginx/sites-enabled/
Test the nginx configuration for syntax errors:
nginx -t
If the test passes, reload nginx to apply the changes:
systemctl reload nginx
At this point, you should be able to access your dashboard at http://your-domain.com.
Install SSL with Certbot
Install Certbot and the nginx plugin:
apt install certbot python3-certbot-nginx
Obtain and install an SSL certificate:
certbot --nginx -d your-domain.com
Certbot will automatically modify your nginx configuration to handle HTTPS and set up automatic certificate renewal.
Certbot sets up a systemd timer to automatically renew your certificates before they expire. You can verify the timer is active with systemctl list-timers | grep certbot.
Update the Dashboard Environment
After SSL is configured, update the NEXTAUTH_URL in your dashboard .env file to use HTTPS:
NEXTAUTH_URL=https://your-domain.com
Restart the dashboard for the change to take effect:
pm2 restart mj-dashboard
If you skip updating NEXTAUTH_URL, authentication redirects will use HTTP instead of HTTPS, which will cause login failures and security warnings.
Verify
Open your browser and navigate to:
https://your-domain.com
You should see the MJ Bot dashboard served over a secure HTTPS connection.
Next Steps
- Authentication -- Configure Discord OAuth2 login for the dashboard.