Sasha
Sasha

Reputation: 8705

Ubuntu 16.04, nginx, phpmyadmin - 502 Bad Gateway

I am using this setting for nginx (default file):

server {
        listen 30425;

        # Don't want to log accesses.
        #access_log  /dev/null main;
        access_log  /var/log/nginx/php.acces_log main;
        error_log   /var/log/nginx/php.error_log info;

        root /usr/share/phpmyadmin;
        index  index.php index.html index.htm;
        error_page 401 403 404 /404.php;

        location ~ .*.php$ {
                include fastcgi_params;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param SERVER_NAME $http_host;
                fastcgi_ignore_client_abort on;

        }
}

When I try to access 30425, I am getting 502 Bad Gateway. All other setting are default one (PHP 7).

Upvotes: 1

Views: 21988

Answers (2)

sumit jaglan
sumit jaglan

Reputation: 46

You have to replace fastcgi_pass 127.0.0.1:9000 or if it is deployed in aws then your IP_ADDRESS; to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; and then it works perfectly.

The path name can vary, so first check the path with /var/run/php-fpm/sock_file_name.sock. Then you should copy the path and paste it to your configuration to avoid silly mistakes.

Hint: sock_file_name can be php7.3-fpm.sock or www.sock etc. So it's depending on your system, don't get confused. All mean the same.

Upvotes: 0

Niyobuhungiro Yves
Niyobuhungiro Yves

Reputation: 71

I had to replace this fastcgi_pass 127.0.0.1:9000;
to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; and then it worked perfectly.

Full code.

server{
    listen 80;
    index index.html index.htm index.php;

    server_name 127.0.0.1;

    root /usr/share/phpmyadmin;
    location / {
            #try_files $uri $uri/ = 404;
            autoindex on;
    }


    location ~\.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+);
            try_files $uri $uri/ =404;
            fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_na$
            fastcgi_param SERVER_NAME $http_host;
            fastcgi_ignore_client_abort on;
    }

}

Upvotes: 4

Related Questions