Setup Custom Domain & Update PUBLIC_URL¶
In this step, we will:
- Point your domain to the VPS
- Configure Nginx to use the domain
- Enable HTTPS (SSL)
- Update
PUBLIC_URL - Restart services
1. Create DNS A Record¶
Go to your domain provider (Namecheap, GoDaddy, Cloudflare, etc.)
Create an A record:
| Type | Name | Value | TTL |
|---|---|---|---|
| A | @ | YOUR_SERVER_IP | Auto |
If using subdomain (recommended):
| Type | Name | Value |
|---|---|---|
| A | dl | YOUR_SERVER_IP |
Example:
2. Verify DNS Propagation¶
On your server:
Or:
It should resolve to your VPS IP.
DNS propagation may take a few minutes.
3. Update Nginx Configuration¶
Edit your site config:
Change:
To:
Save and test:
Reload:
Now test:
It should work over HTTP.
4. Enable HTTPS (Let's Encrypt)¶
Install Certbot:
Run:
Certbot will:
- Generate SSL certificate
- Modify Nginx config automatically
- Enable HTTPS
- Set up auto-renewal
Verify renewal:
Now test:
Cloudflare Users (Important)¶
If your domain is proxied through Cloudflare (orange cloud enabled), you must configure SSL correctly to avoid infinite redirect loops.
Set SSL Mode Properly¶
Go to:
Cloudflare Dashboard → SSL/TLS → Overview
Set SSL mode to:
Full (Strict) ✅ Recommended
Do NOT use:
Flexible ❌ (This will cause redirect loops)
Why Flexible Mode Causes Infinite Redirect
In Flexible mode:
User → Cloudflare (HTTPS)
Cloudflare → Server (HTTP)
Your Nginx then redirects HTTP → HTTPS.
Cloudflare again connects via HTTP.
Result: Infinite redirect loop.
Recommended Cloudflare Settings¶
SSL/TLS → Overview: - SSL Mode: Full (Strict)
SSL/TLS → Edge Certificates: - Always Use HTTPS: ON (Optional but recommended)
5. Update PUBLIC_URL¶
Open .env:
Change:
To:
⚠ PUBLIC_URL must match your final HTTPS domain.
This ensures:
- Download links are generated correctly
- Users receive valid public URLs
6. Restart TG-FileStream¶
After updating .env, restart services:
Restart workers (if any):
sudo systemctl restart tgfs-worker@8081
sudo systemctl restart tgfs-worker@8082
sudo systemctl restart tgfs-worker@8083
Security Recommendations¶
- Always use HTTPS in production
- Keep
DEBUG=False - Do not expose raw worker ports publicly
- Use firewall to block 8080–8084 from external access
Example: