Learn about Centmin Mod LEMP Stack today
Register Now

Nginx 502 Bad Gateway after upgrade

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by NeiPCs, Jul 20, 2014.

  1. NeiPCs

    NeiPCs Member

    40
    9
    8
    Jun 28, 2014
    Ratings:
    +13
    Local Time:
    12:51 PM
    1.11.1
    5.5
    Hello guys,


    I am upgrading server and got some strange issues.
    My website are running over old version of centminmod with nginx v1.2.3, php 5.3.16, APC 3.1.12 and mariadb 5.2.5 (another dedicated server)
    So I worked on code to be fully compatible with changes of php 5.4 and everything work as expected.
    Then I go for newest centminmod instalation over a new droplet with 4GB of ram from DO and got 502 Bad Gateway in certains pages, but phpinfo page always open.

    How can I check where it happens?
    Or what logs are utils to check it?

    After check vhost log I got this error everytime that I open a .php page (except phpinfo):
    - vhost error.log
    2014/07/19 12:00:16 [error] 15525#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: myIP, server: mydomain request: "GET /account-login.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomain", referrer: "mydomain/"

    I've tried some things to fix this:
    - change php-fpm from TCP to UNIX sockets
    - downgraded php to 5.4.29
    - downgraded apc to 3.1.10
    - upgraded nginx to 1.7.3
    - tweak /etc/sysctl.conf for high traffic sites
    - changed phpinc fastcgi_ variables
    - copied all config files from old server, but nothing helped :(
     
  2. eva2000

    eva2000 Administrator Staff Member

    53,558
    12,135
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,678
    Local Time:
    1:51 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    for new Centmin Mod install on new droplet did you go through troubleshooting steps and check install logs etc https://community.centminmod.com/threads/how-to-troubleshoot-centmin-mod-initial-install-issues.102/ ?

    try just restart php-fpm ?

    also i wouldn't of copied old config files as huge changes have happened in Centmin Mod since MariaDB 5.2.x default versions

    Use gist.github.com and post your Nginx vhost contents, php.conf and php-fpm.conf contents and nginx.conf contents.

    Is the new DO droplet just a test server or your live forums now ?
     
    Last edited: Jul 20, 2014
  3. NeiPCs

    NeiPCs Member

    40
    9
    8
    Jun 28, 2014
    Ratings:
    +13
    Local Time:
    12:51 PM
    1.11.1
    5.5
    Yes, everything is OK in logs and phpinfo test page is working as well.
    Yes, I've restarted every time that I've changed something in .fpmconf, phpinc, phpedit or nginxconf or during reinstalls.

    All right, I did it only when nothing more has worked, only for tests trying to figure out what happened.

    OK, Everything is default from centmin install, I guess my php code has something wrong that make it happen, but I don't know how to track it.

    Test server, if it works, then we'll migrate to.

    I'm looking for a replacement server to get out of Softlayer, save money, get some kind of HA.
     
  4. eva2000

    eva2000 Administrator Staff Member

    53,558
    12,135
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,678
    Local Time:
    1:51 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  5. NeiPCs

    NeiPCs Member

    40
    9
    8
    Jun 28, 2014
    Ratings:
    +13
    Local Time:
    12:51 PM
    1.11.1
    5.5
    So,

    I've tested with siege over phpinfo file to see if something is wrong or website isn't supporting concurrent conections, but it seems good.
    Method of test with 2 terminal sessions opened:
    1- added vhost centminmodtest.com
    2- put vhost in /etc/hosts to point 127.0.0.1
    3- leave fpmconf as default from centminmod install:
    [​IMG]

    4- nprestart (to clear previous stats)

    5- benchmark = siege -qb -c 1000 -t 30s http://centminmodtest.com/php_info.php
    [​IMG]

    - phpstatus right after benchmark
    [​IMG]

    All seems OK, and from logs of 502 Bad gateway I got this message on log:
    This website is like a tracker torrent.
     
  6. eva2000

    eva2000 Administrator Staff Member

    53,558
    12,135
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,678
    Local Time:
    1:51 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    well phpinfo.php is a static php page without database backend. If your traffic has a backend database then PHP can timeout and become unresponsive and then Nginx timeouts 502 error waiting on the backend to respond (PHP-FPM) . It's up to you to tune and make sure your specific web app's backend is optimally tuned and/or raise PHP timeouts and settings.

    Unfortunately, never used a torrent tracker myself.
     
  7. NeiPCs

    NeiPCs Member

    40
    9
    8
    Jun 28, 2014
    Ratings:
    +13
    Local Time:
    12:51 PM
    1.11.1
    5.5
    Good point my friend.

    So, I've wrote 2 files:
    1- testapc.php testing functions of APC
    2- testmysql.php with database connection.
    both files are working perfect like phpinfo, so the problem is probably on legacy code from php 5.3.

    I'll look for something wrong and ways to configure php to show me this error or log it.
    I got this kind of error in the past, and was level of error to high, breaking page render instead of display errors on page.
     
  8. eva2000

    eva2000 Administrator Staff Member

    53,558
    12,135
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,678
    Local Time:
    1:51 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    if the torrent php script has an author/support or support forum, might also ask there :)
     
  9. NeiPCs

    NeiPCs Member

    40
    9
    8
    Jun 28, 2014
    Ratings:
    +13
    Local Time:
    12:51 PM
    1.11.1
    5.5
    This is almost impossible to get support in there like you do for us. I've updated a lot since 2010 where original script has gone with your author too... no problem, I have a north to fix it now, I know that is nothing from infra-structure, but in the code. :(

    I've told you today that you're amazing super hyper mega blaster friend that REALLY take care of your apps?
    So, I did it now :D

    Thanks one more time.
     
  10. eva2000

    eva2000 Administrator Staff Member

    53,558
    12,135
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,678
    Local Time:
    1:51 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    You're welcome and thanks for the kind words :)

    It helps that I have a vested stake in making sure Centmin Mod works as 17 out of 20 of my servers run Centmin Mod in live production capacity (including this very forum) + some of my private paying consult clients do use Centmin Mod as well :D