Nginx 502 bad gatway error

Hello,

I’m running a Django application on a Ubuntu server with Nginx and Uwsgi. The application has runned for years and since a couple of days I get a 502 bad gateway error on every request.
Nginx and uwsgi are both active but the nginx/error.log keeps showing :
[error] 1269#1269: *72356 upstream prematurely closed connection while reading response header from upstream, client: 50.170.179.62, server: _,

Can anyone help me out?

What might have happened in the past couple of days?

  • Was the server rebooted?
  • Was any software updated?
  • Were any configuration changes made?

You mention the nginx error log, what about the uwsgi logs? What about your application logs?

Check your system logs as well, look for errors thrown by whatever you’re using to run uwsgi.

Check the existance of the socket file. Does it exist? Does it have the correct permissions?

In the first case the server wasn’t rebooted and I got a 502 error 20% off the time, I tried a reboot to solve this problem and after that I’m always getting the 502 error on every request.
There are no software or configuration changes for the last 8 months.

uwsgi logs: I can only find this file uwsgi-uwsgi.log which is empty.
The syslogs gives the following: but I don’t know if this is a possible cause of a badgateway:


Aug 22 14:39:14 clms uwsgi:
Aug 22 14:39:14 clms uwsgi: raise InvalidKeyError()
Aug 22 14:39:14 clms uwsgi: pushbullet.errors
Aug 22 14:39:14 clms uwsgi: .
Aug 22 14:39:14 clms uwsgi: InvalidKeyError
Aug 22 14:39:14 clms uwsgi:

Yes, that error would be the cause.

(Python 2.7? Really?)

(Side note: I took the liberty of editing your post to surround the log messages with ``` to make them more readable.)

Yeah I know, this is the old server of the customer wich is running for a couple of years.
I’m developing the new one which is up and running but this one is still used.
So I’am the one to solve this problem all well.

However I tried to solve this error to receive new API key and commented some code of pushbullet as well and added a try catch but I keep getting this error.
Do you know anything about this?
This is the file where pushbullet is used

import django
django.setup()

from django.core import exceptions
from pushbullet import Pushbullet, InvalidKeyError


api_key = 'MyKey'
#pb = Pushbullet(api_key)

try:
    pb = Pushbullet(api_key)
    pb.refresh()
except InvalidKeyError:
    # Log the error or notify admins
    print("Invalid Pushbullet API key. Please check your configuration.")
    # You might want to raise an exception or handle it differently






def push_message(title, body):
 #   pb.push_note(title, body)
    return


def push_to_channel(title, body):
    # Get all channels created by the current user
   # my_channel = pb.channels[0]
   # my_channel.push_note(title, body)
    return

I’m sorry, I don’t know anything at all about pushbullet.

But given the potential age of the system and library that you are likely using, there are any number of possible issues to be addressed.

I solved the error of Pushbullet and now it works again, thank you for you help