Reverse Proxy 404

Fix 404 errors when accessing Moltbot through Nginx or Caddy.

Reverse Proxy 404

Getting 404 Not Found errors when accessing Moltbot through your reverse proxy?

Symptoms

  • Browser shows "404 Not Found" from Nginx/Caddy
  • Webhooks fail with 404
  • Direct access to Moltbot port works, but proxied access doesn't

Likely Causes

  1. Proxy path mismatch - proxy forwarding to wrong path
  2. Moltbot not running on expected port
  3. Incorrect upstream configuration
  4. Location block not matching requests
  5. Trailing slash issues

Fix Steps

1. Verify Moltbot is Running

# Check container is running
docker ps | grep moltbot

# Test direct access (bypass proxy)
curl http://localhost:3000/health

2. Check Nginx Configuration

# /etc/nginx/sites-available/moltbot

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:3000;  # Note: no trailing slash
        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;
    }
}

Common issues:

# WRONG - trailing slash changes path handling
proxy_pass http://localhost:3000/;

# CORRECT
proxy_pass http://localhost:3000;

Test configuration:

sudo nginx -t

3. Check Caddy Configuration

# Caddyfile
your-domain.com {
    reverse_proxy localhost:3000
}

With specific path:

your-domain.com {
    handle /api/* {
        reverse_proxy localhost:3000
    }
    handle {
        reverse_proxy localhost:3000
    }
}

4. Check Logs

Nginx:

tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log

Caddy:

journalctl -u caddy -f

Moltbot:

docker logs -f moltbot

5. Test Each Layer

# 1. Test Moltbot directly
curl http://localhost:3000/

# 2. Test proxy locally
curl -H "Host: your-domain.com" http://localhost/

# 3. Test from internet
curl https://your-domain.com/

Verify

After fixing:

# Reload proxy config
sudo systemctl reload nginx  # or: systemctl reload caddy

# Test
curl -I https://your-domain.com/
# Should show HTTP/2 200

Common Mistakes

Forgetting to enable site: For Nginx, symlink must exist:

sudo ln -s /etc/nginx/sites-available/moltbot /etc/nginx/sites-enabled/

Port mismatch: Ensure proxy_pass port matches Moltbot's PORT environment variable.

Firewall blocking local access: Some setups block localhost connections. Check ufw status or iptables -L.