Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dascorp's avatar

Forge 502 Bad Gateway after server restart

Hi everyone, I am struggling with small glitch in Forge/AWS configuration. Please note I don't change any configuration files except .env. So if I "accidentally" or on purpose click "restart server" or "restart nginx service" I get 502 Bad Gateway nginx/1.9.14 I can ssh to the server straight away after restart but the application hosted on the server is not reachable from the server itself. Curl returns 502 as well. After reading most of the "502" posts I gave up and went back to DigitalOcean, but don't want to lose substantial credit value I have on AWS. It happened already 3 times, what is interesting that server is back after period of time, last time it was 3 hours after, maybe server heals itself ;) Could you direct me where to look for, what I think Nginx configuration issue is, to resolve it.

0 likes
5 replies
dascorp's avatar
Level 26

While nobody responded yet, let me add that I did one thing outside forge to rectify this issue I restarted instance in AWS console which obviously changed my IP, but I have changed it to proper value in forge changed DNS records and gained control over SSH back as mentioned above but default page still redirects to old IP which is now taken by different user, is there a way to reset it? I can connect to my server on new IP via ssh but http redirects on all devices to old IP.

huglester's avatar

I would think that best would be to reconfigure IP addresses manually, somewhere in /etc/nginx/

dascorp's avatar
Level 26

The ip is not the issue the problem is nginx restart via forge, note that 502 appeared before I stopped instance via AWS console and restarted it; after restart that IP changed and the ip issue appear. The default site is secondary problem here - 502 on my domains is the thing which prevents me to stay with AWS

dascorp's avatar
Level 26

Hello everyone so it happened again this is what i could extract from the log

2016/05/19 06:55:34 [crit] 11219#11219: *3565 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream,

please note that this is pure forge installation and I don't touch config files.

it looks like nginx php-fpm relationship goes badly on aws ubuntu

1 like
sterling's avatar
sterling
Best Answer
Level 3

I had the same problem, it was pretty obvious after checking that error line that the site was looking for a non-existent version of PHP. I guess Forge is defaulting to a PHP 7 configuration because that's what it installs when it spins up a new server. Unfortunately it doesn't seem to care if an existing server runs PHP 5 when it creates a new site. There may be a setting for this in Forge but I haven't found one.

Anyway, the simple fix for me was to go to the nginx config in:

Forge > [my server] > [mydomain.com] > Edit Files > Edit Nginx Configuration

or in a terminal...

sudo nano /etc/nginx/sites-available/mydomain.com

and change the fastcgi_pass value from unix:/var/run/php/php7.0-fpm.sock to unix:/var/run/php5-fpm.sock as follows:

location @fallback  {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;       # changed from /var/run/php/php7.0-fpm.sock
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root;
        include fastcgi_params;
    }

Please or to participate in this conversation.