Fix a 502 Bad Gateway error on calibre-web

From Parallel Library Services
Revision as of 17:06, 2 November 2021 by Simon (talk | contribs)
Jump to navigation Jump to search
502 bad gateway.jpg

Sometimes, when making changes to the server settings in the calibre-web browser interface, you may get a 502 error. This means that the server isn't responding to HTTP requests. This quick-fix assumes you have SSH access to the machine you are running calibre-web from. If you have local access, even better, you can just restart the server directly.

Connect to the server. In my case, I have the hostname set as parallel-library in my ~/.ssh/config file:

 ssh parallel-library

Activate the python virtual environment

cd parallel_library
source venv/bin/activate

Check to see if nginx is running

systemctl status nginx

Find the process ID (PID) for cps.py (the python script running calibre)

ps -aux | grep python

For me, running this produces:

root     29857  0.3  1.0 297248 83260 ?        Sl   15:09   0:07 python cps.py
root     30054  0.0  0.0   5812   888 pts/0    S+   15:44   0:00 grep python

Note down the number next to this process, the PID. In this case it is 29857.

Then, kill the process (swap out the PID)

kill -9 29857

Run the python script in the background (you can close the terminal after this)

nohup python cps.py

Refresh the page in your browser (do a hard refresh to clear cache) and see if the page reappears. Do a quick uploading/downloading test to make sure it’s all working ok.