502 Bad Gateway Host Server Not Responding (Andasy Deployment)

After successfully deploying my Laravel backend application on Andasy, I am encountering a “502 Bad Gateway error”
when trying to access the API endpoint: https://taskers-api.andasy.dev/api/open/faqs

The error page indicates that:

  • The browser is working
  • Cloudflare is working
  • The host server is returning an error

Observed Behavior:

  • The application URL returns a 502 Bad Gateway error
  • Cloudflare reports Host Error
  • The backend API is not reachable through the domain

Expected Behavior

  • The API endpoint should respond successfully
  • Data should be returned from the backend without errors

I would be happy to provide more details (logs, configuration files, environment variables, or deployment settings) to help diagnose and resolve this issue more effectively

Hi Leon,

What steps to debug have you done? Share more details if possible.

  • Check if your app is running on the same port as the port registered in andasy.hcl
  • Check if your app is listening on ipv6 because we only connect to the ipv6 interface in you machine
  • Run andasy logs to check if you app is started or having issues starting
1 Like

Thank you for your guidance on debugging the 502 Bad Gateway issue. I’ve successfully resolved it!

The problem was: My application was listening on IPv4 only (127.0.0.1), but Andasy requires IPv6 support as you mentioned.

The solution I implemented:

  1. Updated Nginx to listen on both IPv4 and IPv6:
  • listen 80;
  • listen [::]:80;
  1. Switched PHP-FPM from TCP (127.0.0.1:9000) to Unix socket (/var/run/php-fpm.sock), which works seamlessly with both IPv4 and IPv6
  2. Optimized the Dockerfile to use PHP 8.3 instead of 8.4 to reduce build times and avoid deployment timeouts

Current status: Application is now running successfully on https://taskers-api.andasy.dev/api/open/faqs All API endpoints are responding correctly , No more 502 errors

Thanks again for pointing me in the right direction regarding IPv6 connectivity!

1 Like