Fix a 502 Bad Gateway error on calibre-web
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 the configuration settings, which is the file that can be found in the location~/.ssh/config
in most Unix-like systems:
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 all Python scripts running:
ps -aux | grep python
For me, 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
The process running the script cps.py is the one we want to stop, then restart. 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.