Fixing 502 Bad Gateway Nginx


I am coming from youtube video about fixing 502 Bad Gateway Nginx.

I have a Postal SMTP server installed on Ubuntu 18. For a reason I dont know, the server drops and shows 502 bad gatways nginx.

I have followed your debug on youtube and I found this proxy pass message. A backend service that is running on port 5000.


    location @puma {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;

I was not able to discover what service it was.

By chance I tried to start postal service by:

Sudo postal Start

The server returned

Started Procodile supervisor with PID 1227

I tried to access the server from the browser after and it worked!. However, I am not able to send emails event though I am 100% sure of the credentials.

My next step was to debug the SMTP service. and Here are the test returns:

Connected to smtp://
<< 220 ESMTP Postal/LRL1GT
>> EHLO []
<< 250-My capabilities are
<< 334 PDA0Zjg0MWMzZDIxMGRhM2RjMGEzQHBvc3RhbC5teWxpbmt5cy54eXo
>> ZS5jb29rbGVyLmNvbSA2MWUyYjJhNzU1Mzc5NjJhMjRmMzI2MTVmYTI4MmE4Zg==
<< 535 Denied
<< 235 Granted for mailing-system/smtp
<< 250 OK
>> RCPT TO:<>
<< 250 OK
<< 354 Go ahead
>> From:
>> Date: Tue, 29 Dec 2020 10:08:41 퍍
>> Subject: SMTP test from
>> To:
>> MIME-Version: 1.0
>> Content-Type: multipart/alternative; boundary="=-YDkWWl67JIrkb99tqr5XXA=="
>> --=-YDkWWl67JIrkb99tqr5XXA==
>> Content-Type: text/plain; charset=utf-8
>> Test message
>> --=-YDkWWl67JIrkb99tqr5XXA==
>> Content-Type: text/html; charset=utf-8
>> Content-Id: <ZY1RYKPKKCU4.4BNJ84W1Q29U2@WIN-AUIR3RRGP88>
>> <b>Test message</b>
>> --=-YDkWWl67JIrkb99tqr5XXA==--
>> .
ERROR: The SMTP server has unexpectedly disconnected.

I was not able to send a message. So I tried to restart the whole server.

After the server restart I got again the 502 Bad Gateway Nginx error. I fixed it again using the command above and posted here asking for help.

Any ideas on what to do ?

Thank you very much


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @amer001,

It sounds like that the Postal service is crashing for some reason causing the 502 Nginx error.

What I could suggest is checking the logs for that service to see if you could get some more information on why it’s crashing.

According to this FAQs section on GitHub here:

The logs should be located at:


It could be crashing due to various reasons, for example, the server running out of RAM and killing the process.

Feel free to share the errors from the logs here as well. Regards, Bobby