{"id":4135,"date":"2025-10-25T19:32:33","date_gmt":"2025-10-25T14:32:33","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=4135"},"modified":"2025-10-25T19:32:34","modified_gmt":"2025-10-25T14:32:34","slug":"how-to-fix-coolify-bad-gateway-error","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/","title":{"rendered":"How to Fix Coolify Bad Gateway Error"},"content":{"rendered":"\n<p>If you&#8217;re seeing a <strong>&#8220;Bad Gateway&#8221;<\/strong> error when trying to access your Coolify-deployed application through your domain, you&#8217;re not alone. This is one of the most common issues developers face with Coolify, but the good news is that it&#8217;s usually fixable within minutes once you understand what&#8217;s causing it.<\/p>\n\n\n\n<p>Here&#8217;s the deal: your app might be running perfectly fine when you check it via your server&#8217;s IP address and port, but the moment you try to access it through your domain, you hit that frustrating 502 Bad Gateway error. Let&#8217;s fix that.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the Bad Gateway Error in Coolify<\/h2>\n\n\n\n<p>Before we jump into solutions, let&#8217;s quickly understand what&#8217;s happening. When you see a Bad Gateway error in Coolify, it means the Traefik proxy (Coolify&#8217;s default reverse proxy) is trying to reach your application but can&#8217;t establish a connection. Your container might be running, your app might be working internally, but something is blocking the proxy from routing traffic properly.<\/p>\n\n\n\n<p>The most common culprits are port configuration issues, incorrect network settings, or your application listening on the wrong network interface. Let&#8217;s tackle each one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Difference Between Applications and Services in Coolify<\/h2>\n\n\n\n<p>This matters for troubleshooting, so let&#8217;s clarify:<\/p>\n\n\n\n<p><strong>Applications<\/strong> are deployed from Git repositories or other deployment methods (except one-click services). You&#8217;ll see a &#8220;Port Exposes&#8221; field in the dashboard for these.<\/p>\n\n\n\n<p><strong>Services<\/strong> are deployed using Docker Compose files or Coolify&#8217;s one-click service options. These use different network configurations and you might not see the same Network section in your UI.<\/p>\n\n\n\n<p>Keep this distinction in mind as we go through the fixes because the configuration locations differ slightly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Symptoms You&#8217;ll Notice<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your app works when accessed via <code>http:\/\/YOUR_SERVER_IP:PORT<\/code> but fails on your domain<\/li>\n\n\n\n<li>You get a &#8220;No Available Server&#8221; error message<\/li>\n\n\n\n<li>The container shows as &#8220;Running&#8221; in Docker but the domain returns 502<\/li>\n\n\n\n<li>Health checks pass but actual requests fail<\/li>\n\n\n\n<li>Your logs show the app started successfully but it&#8217;s still unreachable<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The Root Causes (And How to Diagnose Them)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Port Configuration Problems<\/h3>\n\n\n\n<p>This is the number one cause of bad gateway errors. Your application is listening on one port inside the container, but Coolify doesn&#8217;t know about it.<\/p>\n\n\n\n<p><strong>For Applications:<\/strong> Check the &#8220;Port Exposes&#8221; field in your Coolify dashboard. This needs to match the exact port your application is listening on inside the container.<\/p>\n\n\n\n<p>For example, if your Node.js app is running on port 3000, that&#8217;s what should be in the Port Exposes field. If your FastAPI app uses 8000, enter 8000. Simple as that.<\/p>\n\n\n\n<p><strong>For Services:<\/strong> Look at your Docker Compose file. Make sure the ports are properly configured in your compose setup and align with how Coolify&#8217;s proxy expects to route traffic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. The Localhost vs 0.0.0.0 Problem<\/h3>\n\n\n\n<p>Here&#8217;s something that catches a lot of developers off guard: if your application is only listening on <code>localhost<\/code> or <code>127.0.0.1<\/code> inside the container, nothing outside that container can reach it. Not Traefik, not the proxy, not anything.<\/p>\n\n\n\n<p>This is because of how Docker networking works. Each container has its own isolated network namespace. When you bind to localhost inside a container, you&#8217;re literally only accepting connections from within that same container.<\/p>\n\n\n\n<p><strong>The fix:<\/strong> Configure your application to listen on <code>0.0.0.0<\/code> instead. This tells your app to accept connections from all network interfaces, which allows the Traefik proxy to connect to it.<\/p>\n\n\n\n<p>Here&#8217;s how to do this for different frameworks:<\/p>\n\n\n\n<p><strong>Node.js\/Express:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">app.listen(3000, '0.0.0.0', () =&gt; {\n  console.log('Server running on 0.0.0.0:3000');\n});\n<\/pre><\/div>\n\n\n\n<p><strong>FastAPI\/Python:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">if __name__ == &quot;__main__&quot;:\n    uvicorn.run(app, host=&quot;0.0.0.0&quot;, port=8000)\n<\/pre><\/div>\n\n\n\n<p><strong>Flask:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">if __name__ == '__main__':\n    app.run(host='0.0.0.0', port=5000)\n<\/pre><\/div>\n\n\n\n<p><strong>Laravel\/PHP:<\/strong> In your <code>.env<\/code> file or server configuration, make sure PHP-FPM or your web server is configured to accept connections from the Docker network, not just localhost.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Host Port Mapping Conflicts<\/h3>\n\n\n\n<p>If you&#8217;ve added port mappings in your Docker Compose file (like <code>\"8888:80\"<\/code>), this can interfere with how Coolify&#8217;s proxy routes traffic.<\/p>\n\n\n\n<p>When you manually map a port to the host, you&#8217;re bypassing Coolify&#8217;s internal routing mechanism. The proxy expects to connect to your container through Docker&#8217;s internal network, but the port mapping makes it accessible directly on the host instead.<\/p>\n\n\n\n<p><strong>The solution:<\/strong> Remove the port mappings from your compose file and let Coolify handle the routing. The proxy will automatically route traffic to the correct container port.<\/p>\n\n\n\n<p>Before (causes issues):<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;yaml&quot;,&quot;mime&quot;:&quot;text\/x-yaml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;YAML&quot;,&quot;language&quot;:&quot;YAML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;yaml&quot;}\">services:\n  app:\n    image: nginx:latest\n    ports:\n      - &quot;8888:80&quot;  # Remove this\n<\/pre><\/div>\n\n\n\n<p>After (works correctly):<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;yaml&quot;,&quot;mime&quot;:&quot;text\/x-yaml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;YAML&quot;,&quot;language&quot;:&quot;YAML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;yaml&quot;}\">services:\n  app:\n    image: nginx:latest\n    # No ports mapping - let Coolify\/Traefik handle routing\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">4. Container Health and Status Issues<\/h3>\n\n\n\n<p>Sometimes the bad gateway happens because the container itself is having problems.<\/p>\n\n\n\n<p><strong>What to check:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Is the container stuck at &#8220;Starting&#8221; status?<\/li>\n\n\n\n<li>Is the health check failing?<\/li>\n\n\n\n<li>Did the container crash after starting?<\/li>\n<\/ul>\n\n\n\n<p>Check your application logs in Coolify. Look for error messages during startup. Common issues include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Missing environment variables<\/li>\n\n\n\n<li>Database connection failures<\/li>\n\n\n\n<li>Permission problems with files or directories<\/li>\n\n\n\n<li>Dependency installation failures<\/li>\n<\/ul>\n\n\n\n<p>If the health check is causing problems and you&#8217;ve verified your app is actually running, you might need to adjust or temporarily disable the health check to get things working.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Storage and Resource Limitations<\/h3>\n\n\n\n<p>This one is sneaky. If your server runs out of disk space, memory, or other resources, Coolify itself can start throwing Bad Gateway errors, including on its own dashboard.<\/p>\n\n\n\n<p>Check your server resources:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Shell&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">df -h  # Check disk space\nfree -h  # Check memory\ndocker system df  # Check Docker disk usage\n<\/pre><\/div>\n\n\n\n<p>If you&#8217;re running low on space, clean up unused Docker resources:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Shell&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">docker system prune -a --volumes\n<\/pre><\/div>\n\n\n\n<p>Just be careful with this command as it removes stopped containers, unused networks, and dangling images.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-Step Fix Guide<\/h2>\n\n\n\n<p>Let&#8217;s walk through fixing this systematically:<\/p>\n\n\n\n<p><strong>Step 1: Verify Your Port Configuration<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>SSH into your container or check your application code<\/li>\n\n\n\n<li>Find what port your app is listening on<\/li>\n\n\n\n<li>In Coolify&#8217;s dashboard, go to your application&#8217;s settings<\/li>\n\n\n\n<li>Update the &#8220;Port Exposes&#8221; field with the correct port number<\/li>\n\n\n\n<li>Save and redeploy<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 2: Check the Listening Address<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Look at your application&#8217;s startup code<\/li>\n\n\n\n<li>Make sure it&#8217;s binding to <code>0.0.0.0<\/code>, not <code>localhost<\/code> or <code>127.0.0.1<\/code><\/li>\n\n\n\n<li>Update your code if needed<\/li>\n\n\n\n<li>Commit and redeploy<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 3: Remove Host Port Mappings<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open your Docker Compose file (if using one)<\/li>\n\n\n\n<li>Remove any <code>ports:<\/code> sections that map to the host<\/li>\n\n\n\n<li>Let Coolify handle the routing through Traefik<\/li>\n\n\n\n<li>Redeploy your service<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 4: Add the Port to Your Domain URL<\/strong><\/p>\n\n\n\n<p>If you&#8217;re using a non-standard port, you might need to include it in your domain configuration in Coolify.<\/p>\n\n\n\n<p>For example, if your app listens on port 8000, configure your domain as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>https:\/\/yourdomain.com:8000<\/code><\/li>\n<\/ul>\n\n\n\n<p>Coolify will handle routing external traffic from port 80\/443 to your app&#8217;s internal port 8000.<\/p>\n\n\n\n<p><strong>Step 5: Check Container Logs and Health<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>View your application logs in Coolify<\/li>\n\n\n\n<li>Look for startup errors or connection issues<\/li>\n\n\n\n<li>Check the container status in the dashboard<\/li>\n\n\n\n<li>If health checks are failing, review the health check command<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 6: Test the Container Internally<\/strong><\/p>\n\n\n\n<p>Before dealing with proxy issues, verify your app works inside the container:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Shell&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">docker exec -it YOUR_CONTAINER_NAME curl http:\/\/localhost:YOUR_PORT\n<\/pre><\/div>\n\n\n\n<p>If this works, the problem is definitely with the proxy routing. If this fails, your app itself has issues.<\/p>\n\n\n\n<p><strong>Step 7: Inspect Traefik Proxy Logs<\/strong><\/p>\n\n\n\n<p>Check what Traefik is seeing:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Shell&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">docker logs -f coolify-proxy\n<\/pre><\/div>\n\n\n\n<p>Look for connection refused errors, timeout messages, or routing issues. These logs will often tell you exactly what&#8217;s wrong.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advanced Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Network Isolation Issues<\/h3>\n\n\n\n<p>If you&#8217;ve defined custom Docker networks in your compose file, this can cause problems. Coolify&#8217;s proxy runs in its own network, and your app runs in your custom network. They can&#8217;t talk to each other.<\/p>\n\n\n\n<p><strong>Solution:<\/strong> Let Coolify manage networks automatically. Remove custom network definitions and use Coolify&#8217;s destination configuration instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Multiple Services Sharing Resources<\/h3>\n\n\n\n<p>If you&#8217;re running multiple applications and they&#8217;re conflicting over ports or resources, you&#8217;ll see intermittent bad gateway errors.<\/p>\n\n\n\n<p>Make sure each application uses unique ports and that no two services are trying to bind to the same port on the host.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DNS and SSL Certificate Problems<\/h3>\n\n\n\n<p>Sometimes what looks like a bad gateway is actually a DNS or SSL issue.<\/p>\n\n\n\n<p><strong>Verify:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your domain&#8217;s DNS records point to your server&#8217;s IP<\/li>\n\n\n\n<li>SSL certificates are properly generated (check Traefik dashboard)<\/li>\n\n\n\n<li>You&#8217;re not mixing HTTP and HTTPS incorrectly<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Checking Traefik Configuration<\/h3>\n\n\n\n<p>You can view Traefik&#8217;s dynamic configuration through the dashboard:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to Server settings in Coolify<\/li>\n\n\n\n<li>Navigate to Proxy tab<\/li>\n\n\n\n<li>Check Dynamic Configurations<\/li>\n<\/ol>\n\n\n\n<p>Look for routing rules that match your application. Make sure the service backend points to the correct container and port.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Real-World Examples<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Example 1: Node.js App with Wrong Binding<\/h3>\n\n\n\n<p><strong>Problem:<\/strong> FastAPI app shows &#8220;Running&#8221; but domain returns Bad Gateway.<\/p>\n\n\n\n<p><strong>Diagnosis:<\/strong> App was binding to localhost only.<\/p>\n\n\n\n<p><strong>Fix:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\"># Before\nuvicorn.run(app, host=&quot;127.0.0.1&quot;, port=8000)\n\n# After  \nuvicorn.run(app, host=&quot;0.0.0.0&quot;, port=8000)\n<\/pre><\/div>\n\n\n\n<p>Result: App immediately accessible through domain.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 2: Laravel with Port Mapping<\/h3>\n\n\n\n<p><strong>Problem:<\/strong> Laravel app accessible on server IP with port but Bad Gateway on domain.<\/p>\n\n\n\n<p><strong>Diagnosis:<\/strong> Docker Compose had port mapping that bypassed Coolify&#8217;s proxy.<\/p>\n\n\n\n<p><strong>Fix:<\/strong> Removed <code>ports: - \"8000:80\"<\/code> from compose file, let Traefik handle routing.<\/p>\n\n\n\n<p>Result: Domain worked perfectly after redeployment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 3: Wrong Port Configuration<\/h3>\n\n\n\n<p><strong>Problem:<\/strong> Nginx service showing Bad Gateway.<\/p>\n\n\n\n<p><strong>Diagnosis:<\/strong> Coolify was configured for port 80, but the custom Nginx config was listening on 8080.<\/p>\n\n\n\n<p><strong>Fix:<\/strong> Updated Port Exposes field from 80 to 8080.<\/p>\n\n\n\n<p>Result: Instant fix, no redeployment needed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prevention Tips<\/h2>\n\n\n\n<p>Once you&#8217;ve fixed your bad gateway error, here&#8217;s how to avoid it in the future:<\/p>\n\n\n\n<p><strong>1. Always Configure Listen Address First<\/strong><\/p>\n\n\n\n<p>When starting a new project, immediately set your application to listen on <code>0.0.0.0<\/code>. Make this a standard practice.<\/p>\n\n\n\n<p><strong>2. Document Your Ports<\/strong><\/p>\n\n\n\n<p>Keep a note of which port each application uses. This makes configuration much faster.<\/p>\n\n\n\n<p><strong>3. Test Locally with Docker First<\/strong><\/p>\n\n\n\n<p>Before deploying to Coolify, test your Docker setup locally. Make sure your app is accessible from outside the container.<\/p>\n\n\n\n<p><strong>4. Use Environment Variables for Configuration<\/strong><\/p>\n\n\n\n<p>Instead of hardcoding ports and hosts, use environment variables:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const PORT = process.env.PORT || 3000;\nconst HOST = process.env.HOST || '0.0.0.0';\napp.listen(PORT, HOST);\n<\/pre><\/div>\n\n\n\n<p><strong>5. Check Health Check Commands<\/strong><\/p>\n\n\n\n<p>Make sure your health check commands work reliably. A failing health check can cause Coolify to mark your app as unavailable even when it&#8217;s running.<\/p>\n\n\n\n<p><strong>6. Monitor Resource Usage<\/strong><\/p>\n\n\n\n<p>Keep an eye on disk space, memory, and CPU. Set up alerts if possible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When to Ask for Help<\/h2>\n\n\n\n<p>If you&#8217;ve tried everything above and still have issues, it&#8217;s time to reach out for support. But before you do, gather this information:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your application logs from Coolify<\/li>\n\n\n\n<li>Coolify proxy logs (<code>docker logs coolify-proxy<\/code>)<\/li>\n\n\n\n<li>Screenshots of your configuration (port settings, domain config, etc.)<\/li>\n\n\n\n<li>A description of what you&#8217;ve already tried<\/li>\n\n\n\n<li>Your Docker Compose file (if using one)<\/li>\n<\/ul>\n\n\n\n<p>The Coolify community is active and helpful. Join their Discord server and share this information in the support channel.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<p><strong>Q: Why does my app work with IP:port but not with the domain?<\/strong><\/p>\n\n\n\n<p>This is the classic bad gateway scenario. It means your app is running and accessible directly, but Traefik can&#8217;t route to it. Check your port configuration in Coolify and make sure your app is listening on 0.0.0.0, not localhost.<\/p>\n\n\n\n<p><strong>Q: Do I need to expose ports in my Docker Compose file for Coolify?<\/strong><\/p>\n\n\n\n<p>No, and you probably shouldn&#8217;t. Coolify and Traefik handle routing internally. Exposing ports with host mappings can actually cause conflicts. Let Coolify manage the routing.<\/p>\n\n\n\n<p><strong>Q: My application logs show it&#8217;s running on 0.0.0.0:8000 but I still get Bad Gateway. What&#8217;s wrong?<\/strong><\/p>\n\n\n\n<p>Check two things: First, is the Port Exposes field in Coolify set to 8000? Second, are there any health checks failing? Look at the container status in Coolify&#8217;s dashboard.<\/p>\n\n\n\n<p><strong>Q: Can I use a custom port for my application?<\/strong><\/p>\n\n\n\n<p>Yes, absolutely. Just make sure the Port Exposes field in Coolify matches your app&#8217;s port. If you need to access it on a specific external port, include that in your domain configuration (like <code>yourdomain.com:8000<\/code>).<\/p>\n\n\n\n<p><strong>Q: What&#8217;s the difference between localhost and 0.0.0.0?<\/strong><\/p>\n\n\n\n<p>Localhost (127.0.0.1) only accepts connections from the same machine. In Docker, that means only from within the same container. 0.0.0.0 accepts connections from any network interface, allowing Traefik to connect from outside the container.<\/p>\n\n\n\n<p><strong>Q: How do I check if my app is actually listening on the correct port?<\/strong><\/p>\n\n\n\n<p>SSH into the container and run: <code>netstat -tulnp<\/code> or <code>ss -tulnp<\/code>. You&#8217;ll see what ports are open and what&#8217;s listening. Or use: <code>docker exec YOUR_CONTAINER curl localhost:YOUR_PORT<\/code><\/p>\n\n\n\n<p><strong>Q: Why does my app work in development but not in Coolify?<\/strong><\/p>\n\n\n\n<p>Usually because of how you&#8217;re running the development server. Many dev servers default to localhost only. Make sure your production configuration explicitly sets the host to 0.0.0.0.<\/p>\n\n\n\n<p><strong>Q: Will removing port mappings break my application?<\/strong><\/p>\n\n\n\n<p>No, Traefik will still route traffic to your application through Docker&#8217;s internal networking. Your app remains accessible through the domain, but not through direct host port access.<\/p>\n\n\n\n<p><strong>Q: How long does it take for fixes to take effect?<\/strong><\/p>\n\n\n\n<p>Port configuration changes are usually instant (sometimes requiring a restart). Code changes that modify the listening address require a full redeployment. DNS changes can take minutes to hours to propagate.<\/p>\n\n\n\n<p><strong>Q: Can resource limitations cause Bad Gateway errors?<\/strong><\/p>\n\n\n\n<p>Yes. If your server runs out of disk space or memory, containers can fail to start or crash intermittently, causing bad gateway errors. Always monitor your server resources.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Bad Gateway errors in Coolify are frustrating, but they&#8217;re almost always caused by a handful of common configuration issues. In most cases, the fix is simple: ensure your app listens on 0.0.0.0, verify your port configuration matches what your app actually uses, and remove any manual port mappings that interfere with Traefik&#8217;s routing.<\/p>\n\n\n\n<p>The key is systematic troubleshooting. Start with the basics (ports and listening addresses), check your logs for clues, and work your way through the checklist above. Most bad gateway issues resolve within minutes once you identify the root cause.<\/p>\n\n\n\n<p>Remember that Coolify is designed to make deployment easier, and once you understand how its proxy system works, you&#8217;ll be able to diagnose and fix these issues quickly. The Docker networking layer, while powerful, can be counterintuitive at first, especially the localhost vs 0.0.0.0 distinction.<\/p>\n\n\n\n<p>Keep experimenting, check those logs, and don&#8217;t hesitate to reach out to the Coolify community when you&#8217;re stuck. Happy deploying!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re seeing a &#8220;Bad Gateway&#8221; error when trying to access your Coolify-deployed application through your domain, you&#8217;re not alone. This is one of the most common issues developers face with Coolify, but the good news is that it&#8217;s usually fixable within minutes once you understand what&#8217;s causing it. Here&#8217;s the deal: your app might &#8230; <a title=\"How to Fix Coolify Bad Gateway Error\" class=\"read-more\" href=\"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/\" aria-label=\"Read more about How to Fix Coolify Bad Gateway Error\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":1762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[115],"tags":[],"class_list":["post-4135","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guides"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Fix Coolify Bad Gateway Error<\/title>\n<meta name=\"description\" content=\"If you&#039;re seeing a &quot;Bad Gateway&quot; error when trying to access your Coolify-deployed application through your domain, you&#039;re not alone. This is one of the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Fix Coolify Bad Gateway Error\" \/>\n<meta property=\"og:description\" content=\"If you&#039;re seeing a &quot;Bad Gateway&quot; error when trying to access your Coolify-deployed application through your domain, you&#039;re not alone. This is one of the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-25T14:32:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-25T14:32:34+00:00\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Fix Coolify Bad Gateway Error","description":"If you're seeing a \"Bad Gateway\" error when trying to access your Coolify-deployed application through your domain, you're not alone. This is one of the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/","og_locale":"en_US","og_type":"article","og_title":"How to Fix Coolify Bad Gateway Error","og_description":"If you're seeing a \"Bad Gateway\" error when trying to access your Coolify-deployed application through your domain, you're not alone. This is one of the","og_url":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2025-10-25T14:32:33+00:00","article_modified_time":"2025-10-25T14:32:34+00:00","author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"How to Fix Coolify Bad Gateway Error","datePublished":"2025-10-25T14:32:33+00:00","dateModified":"2025-10-25T14:32:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/"},"wordCount":2190,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","articleSection":["Guides"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/","url":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/","name":"How to Fix Coolify Bad Gateway Error","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2025-10-25T14:32:33+00:00","dateModified":"2025-10-25T14:32:34+00:00","description":"If you're seeing a \"Bad Gateway\" error when trying to access your Coolify-deployed application through your domain, you're not alone. This is one of the","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","width":880,"height":495,"caption":"Default Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/how-to-fix-coolify-bad-gateway-error\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Fix Coolify Bad Gateway Error"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/4135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=4135"}],"version-history":[{"count":1,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/4135\/revisions"}],"predecessor-version":[{"id":4136,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/4135\/revisions\/4136"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1762"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=4135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=4135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=4135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}