3

I have a site built in Drupal 7 on a nginx server. A few times a week when I edit any content and press save, or when I log in to the site, or when I change some configuration, I get a white screen with the message "502 Bad gateway". The error is never showed to anonymous visitors, only when logged in and saving changes. It doesn't seem to matter what kind of changes I do. I can press the back button in the browser, which takes me back to the edit screen and press save again, and save the change successfully.

The error happened again this morning at 08:09, so I looked at the PHP log:

2016/10/20 08:09:00 [error] 20703#20703: *3297348 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 195.198.76.66, server: www.example.com, request: "POST /node/88/edit HTTP/1.1", upstream: "fastcgi://unix:/run/php/php-fpm.sock:", host: "www.example.com", referrer: "http://www.example.com/node/88/edit"

And here is the nginx log at that same time:

[20-Oct-2016 08:09:00] WARNING: [pool www0] child 10909, script '/srv/www/example/public_html/index.php' (request: "POST /index.php") execution timed out (8189.954999 sec), terminating
[20-Oct-2016 08:09:00] WARNING: [pool www0] child 10909 exited on signal 15 (SIGTERM) after 19080.476683 seconds from start
[20-Oct-2016 08:09:00] NOTICE: [pool www0] child 13002 started

Can anyone see what is happening here?

3 Answers 3

3

I had a HTTP 502 problem on a setup with nginx & php-fpm. It seems that many timeouts & limits must be modified according to the data transfer time. What was happening in this case is that the keepalive timeout was too short.

Here are some settings that might help solve 502 problems:

  • In nginx.conf: keepalive_timeout
  • In the site's configuration file (which is in thesites-available folder):
    • send_timeout
    • fastcgi_connect_timeout
    • fastcgi_send_timeout
    • fastcgi_read_timeout
  • in php.ini:
    • max_execution_time
    • max_input_time

The real source of the problem can be any of these settings.

1
  • The bad gateway means a timeout between nginx and the backend. This could mean a longer max_execution_time than the fastcgi timeouts in nginx and a script, which actually uses the execution time. If php kills the script, you should not get a bad gateway but some php error.
    – allo
    Feb 16, 2017 at 22:23
1

It would be worth checking your Drupal logs for any further information. It sounds like you have a module which is triggering a script thats taking too long to complete. Given that it happens when you are logged in as the admin, it could be the cron taking to long to complete.

Try manually triggering the cron to see if the error occurs, then check drupal/nginx logs.

You could change the max_execution_time value in your php.ini config for php-fpm, though this will likely just cover up the problem and work as a quick fix. You're best to find the problem which is happening in Drupal and try and resolve that.

2
  • Thanks for your answer. I did actually look in the Drupal logs and I coudn't see anything out of the ordinary. What do you think about the > 8000 seconds time out above: 'execution timed out (8189.954999 sec)'? There is something going on but I am not sure what it is. I will look into the cron issue too.
    – TBJ
    Oct 21, 2016 at 14:35
  • As a matter of fact, I don't use the internal cron, An external crontab.is setup on the server. But I guess it can still be the cron taking too long.
    – TBJ
    Oct 21, 2016 at 14:50
1

Whenever I have encountered 502 with nginx -- 90% of the time it was something to do with php-fpm

Try to reproduce the issue -- tail php-fpm logs and see if you need to tweak something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.