I have spent almost the entire day debugging this issue with my phpmyadmin installation getting error 404 when I run it using Nginx. I have Googled several pages online, but no solution has worked. However, when I run phpmyadmin as a domain, it works!!
I want to access phpmyadmin as directory such as http://my-server-ip/phpmyadmin
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /phpmyadmin {
access_log /var/log/nginx/phpmyadmin_access.log;
error_log /var/log/nginx/phpmyadmin_error.log;
root /usr/share/phpmyadmin;
index index.php;
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/index.php;
fastcgi_param SCRIPT_NAME /index.php;
}
location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
}
}
You got 404 because nginx is looking for 'phpmyadmin' in '/usr/share/phpmyadmin/'. It means '/usr/share/phpmyadmin/phpmyadmin' Replace 'root' with 'alias' https://nginx.ru/en/docs/http/ngx_http_core_module.html#alias to solve it.
example:
I finally got it working with the following config;