Question

Fixing 502 Bad Gateway Nginx

Posted December 29, 2020 4.3k views
NginxApache

Hi,

I am coming from youtube video https://www.youtube.com/watch?v=obRxID54H14&list=PLEw57Zr9GItiqmK7RJgqvAr5593HGmu7Q&index=2&t=219s
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;
        proxy_pass http://127.0.0.1:5000;
    }

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://postal.mylinkys.xyz:25/?starttls=when-available
<< 220 postal.mylinkys.xyz ESMTP Postal/LRL1GT
>> EHLO [172.31.10.74]
<< 250-My capabilities are
<< 250 AUTH CRAM-MD5 PLAIN LOGIN
>> AUTH CRAM-MD5
<< 334 PDA0Zjg0MWMzZDIxMGRhM2RjMGEzQHBvc3RhbC5teWxpbmt5cy54eXo
>> ZS5jb29rbGVyLmNvbSA2MWUyYjJhNzU1Mzc5NjJhMjRmMzI2MTVmYTI4MmE4Zg==
<< 535 Denied
>> AUTH PLAIN AGUuY29va2xlci5jb20AU3RDSlU5MjBhNTRjZkF1a09OOVZPTFNP
<< 235 Granted for mailing-system/smtp
>> MAIL FROM:<care@XXXXXXX.com>
<< 250 OK
>> RCPT TO:<mr.XXXXXX@gmail.com>
<< 250 OK
>> DATA
<< 354 Go ahead
>> From: care@XXXXX.com
>> Date: Tue, 29 Dec 2020 10:08:41 퍍
>> Subject: SMTP test from postal.mylinkys.xyz
>> Message-Id: <ZY1RYKPKKCU4.DT6UMYJYPLES3@WIN-AUIR3RRGP88>
>> To: mr.XXXXX@gmail.com
>> 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

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.

×
Submit an Answer
1 answer

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:

https://github.com/postalhq/postal/wiki/FAQs

The logs should be located at:

/opt/postal/app/log

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