dimabuko
By:
dimabuko

502 Bad Gateway nginx/1.10.3 (Ubuntu) after migrating Wordpress from another hosting

October 3, 2017 2.3k views
Nginx WordPress Ubuntu Ubuntu 16.04

Hello,

I am trying to run my Wordpress based website after migration from another hosting.
Last time I did it it worked well but after my last successful migration I updated to Ubuntu 16.04.3.

Now I have 502 Bad Gateway nginx/1.10.3 (Ubuntu).

I tried to check log file /var/log/nginx/error.log β€” this file is empty πŸ˜•
I tried some advises from another threads (restarting nginx and php5-fpm) β€” it doesn't help.

Please give me any advise how to find out the reason.

2 comments
  • Could you show your nginx.conf file?

  • Hello,
    I have the same problem since 2 weeks on my droplet with all php installations am trying to run.
    I purged all nginx, php* packages then reinstall it again an set again all my vhost conf and it was working since yesterday.. all my wordpress sites. But, am just coming to get the same problem now.
    My phpmyadmin new installation (after the previous apt purge) is a manualy installation with phpmyadmin archive: it brings me 502 too exactly like a phpinfo(); file . But any problem with Html site, on the sames vhost or not.

    Bellow is the /etc/nginx/sites-available/ conf for one installation with a single index.php file

    ##BLOC DE SITE##
    server {
            listen 80;
    
            root /home/orineltux/web/ubuntufacile/public_html;
            index index.php index.html index.htm;
    
            server_name ubuntufacile.tk www.ubuntufacile.tk;
    
            location / {
    #               try_files $uri $uri/ =404;
                    try_files $uri $uri/ /index.php?q=$uri$args;
            }
    
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
    }
    
    # Nouveau Bloc pour les parametres additionnels
    server {
            # CONFIGURATION SSL
            listen 443 ssl http2;
            listen [::]:443 ssl http2;
            include snippets/ssl-ubuntufacile.tk.conf;
            include snippets/ssl-params.conf;
            server_name ubuntufacile.tk www.ubuntufacile.tk;
            root /home/orineltux/web/ubuntufacile/public_html;
            index index.php index.html index.htm;
    
            location / {
            ##try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php$is_args$args;
            }
    
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
    
    ####POUR LETSENCRYPT############
            location ~ /.wel-known {
                    allow all;
            }
    }
    
    
3 Answers

Hello,
I have the same problem since 2 weeks on my droplet with all php installation am trying to run.
I purged all nginx, php* then reinstall it again an set again all my vhost conf and it was working since yesterday.. all my wordpress sites. But, am just coming to get the same problem now.
My phpmyadmin new installation (after the previous apt purge) is a manualy installation with phpmyadmin archive: it brings me 502 too exactly like a phpinfo(); file . But any problem with Html site, on the sames vhost or not.

The /var/log/nginx/error.log last lines with me is:

2017/11/03 15:32:31 [error] 11344#11344: *8081 connect() to unix:/var/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 82.145.223.13, server: ubuntufacile.tk, request: $

I can deduct that it is realy a php-fpm communication failed.

So, I try to change the FastCgi request path wich was "/run/php/php7.0-fpm.sock" in the file /etc/php/7.0/fpm/pool.d/www-conf by "127.0.0.1:9000" and do the same with the fastcgi parameter in my vhosts conf files. Then, i reload php-fpm and nginx service and my sites are back again.

in the /etc/php/7.0/fpm/pool.d/www-conf:
Comment this line with (;) prefixe

;listen = /run/php/php7.0-fpm.sock 

then add bellow

listen = 127.0.0.1:9000;

Then, in the site conf file, (/etc/nginx/sites-available/)
Comment this line with (#) prefixe

#fastcgi_pass /var/run/php/php7.0-fpm.sock;

then add bellow the line

fastcgi_pass 127.0.0.1:9000;

I hope just it is fix for ever despite of an futur packages upgrade, because, i'd try the same method before without success, reason for my previous apt purge and reinstall. Although, i used a single different socket php-fpm pool for each site/vhost before have the trouble lastly. It worked kindly during several months.

Sorry for my english.. I'm french speaker

Have another answer? Share your knowledge.