MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Server (https://www.mobileread.com/forums/forumdisplay.php?f=277)
-   -   502 Bad Gateway errors on nginx server (https://www.mobileread.com/forums/showthread.php?t=337807)

georgehuang 03-05-2021 11:02 PM

502 Bad Gateway errors on nginx server
 
I now have Calibre Content Server running with nginx as a virtual host, which has received a SSL certificate from Certbot for security's sake. They all run on Ubuntu 20.04 on a VPS. And I also set up a startup service that runs Calibre:

Code:

/opt/calibre/calibre-server /home/ubuntu/Calibre --enable-local-write --enable-auth --auth-mode "basic" --ban-after 5 --ban-for 5 --log /home/ubuntu/log/calibre.log
Most of the time Calibre runs great, but I get 502 Bad Gateway error about twice or thrice a day. I have logs enabled but calibre.log does not show anything related. nginx's error.log do have reports like:

Code:

[error] 641#641: *1773 connect() failed (111: Connection refused) while connecting to upstream ...
This can be easily fixed by restarting Calibre server, without having to restart nginx. However, that means I will have to ssh into my VPS and run the command, which is not as easy to do when I am out with only a mobile phone.

Any idea why this might happen? Is there anything I can do to fix this?

kovidgoyal 03-05-2021 11:22 PM

You sure there is nothing in the calibre server logs? Does it happen after doing a particular type of activity?

georgehuang 03-06-2021 03:25 AM

Yes, nothing on calibre.log other than the normal:

Code:

calibre server listening on 0.0.0.0:8080
OPDS feeds advertised via BonJour at: ....

Weirdly, 502 Bad Gateway happens quite randomly. Mostly it happens when I am doing nothing at all; went to bed and wake up with 502, for example. Happened twice while I was reading and taking notes, as far as I can remember.

kovidgoyal 03-06-2021 06:15 AM

Without anything in the logs I cant really help you. Other than to suggest that you make sure you are running the official calibre binaries and not the distro packaed version of calibre.

georgehuang 03-06-2021 09:17 AM

Understood. And yes, I am using the official binaries. Will try to get more info if I can.

georgehuang 03-31-2021 04:21 AM

I think I figured out what went wrong.

So my VPS instance has only 512 MBs of RAM. Although all it does is running Calibre Content Server on nginx, it still runs out of memory through time. And when the memory runs out on a Linux machine, something named Out of Memory (OOM) killer is triggered and kills Calibre, which results in nginx not being able to connect to the backend so finally "502 Bad Gateway".

I added 1GB of swap memory to my instance, and Calibre has not been killed since then.


All times are GMT -4. The time now is 05:35 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.