0
votes

I'm studying centos7 and nginx. I can display index.html with cerbot SSL. And I installed phpmyAdmin then I open https://mywebsite.com/phpMyAdmin/ I got 502 Bad Gateway errir Could someone teach me right way please?

Here is my log.

2021/05/01 17:23:08 [error] 15816#15816: *103 connect() failed (111: Connection refused) while connecting to upstream, client: 125.xxx.xxx.xx, server: mywebsite.com, request: "GET /phpMyAdmin/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mywebsite.com"

2021/05/01 17:23:09 [error] 15816#15816: *103 open() "/var/www/html/favicon.ico" failed (2: No such file or directory), client: 125.xxx.xxx.xx, server: mywebsite.com, request: "GET /favicon.ico HTTP/1.1", host: "mywebsite.com"

Here is my nginx.conf

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

server {
    listen  443 ssl;
    server_name     mywebiste.com;


    root /var/www/html;

location / {
index index.php index.html index.htm;
}

location ^~ /blog {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://127.0.0.1:2368;
  }

location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

And here is my /etc/nginx/conf.d/default.conf server {

    location /phpMyAdmin {
        alias /usr/share/phpMyAdmin/;
        try_files $uri $uri/ /index.php;

        location ~ ^/phpMyAdmin/(.+\.php)$ {
            alias /usr/share/phpMyAdmin;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin/$1;
            include fastcgi_params;
            fastcgi_intercept_errors on;
            allow XXX.XXX.XX.XX;  # 
            deny  all;            # 
        }
    }     

}

UPDATE(I did Dear qwsj answer,after that Here is my update.)

I installed phpmyadmin at /usr/share/phpMyAdmin

ln -s /usr/share/phpMyAdmin /var/www/html/mywebisite/phpmyadmin

I open https://mywebisite/phpmyadmin/

error log says directory index of "/var/www/html/mywebisite/phpmyadmin/" is forbidden,

1

1 Answers

1
votes

In error log upstream: "fastcgi://127.0.0.1:9000" but in config you use unix socket (mb you dont make a reload/restart?).

Check the php-fpm config (variable listen), what is the real path to socket /var/run/php-fpm.sock or /var/run/php-fpm/php-fpm.sock?

Also, after this, check listen permission for php-fpm, the user must be identical to the user in nginx config (nginx.conf). PHP-FPM Pool config eg:

listen.owner = nginx
listen.group = nginx

Nginx config eg:

user nginx;

UPD: Please check SELinux status, need disabled it:

[root ~]# sestatus
SELinux status:                 enabled
...

Update SELinix /etc/selinux/config from SELINUX=enforcing to SELINUX=disabled. After this, need reboot. After reboot:

[root ~]# sestatus
SELinux status:                 disabled
[root ~]#

Config on my test:

    location /phpMyAdmin {
        root /usr/share;
        index index.php index.html index.htm;
        location ~ ^/phpMyAdmin/(.+\.php)$ {
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_intercept_errors on;
        }
    }

Dont make a symlink ln -s /usr/share/phpMyAdmin /var/www/html/mywebisite/phpmyadmin, its not needed