我花了几乎一整天的时间调试这个问题,当我使用 Nginx 运行 phpmyadmin 时,出现 404 错误。我在网上搜索了几个页面,但没有找到解决办法。但是,当我以域的形式运行 phpmyadmin 时,它就起作用了!!
我想以目录形式访问 phpmyadmin,例如http://我的服务器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;
}
}
答案1
你得到 404 因为 nginx 正在寻找'phpmyadmin' 在 '/usr/share/phpmyadmin/”。意思是“/usr/share/phpmyadmin/phpmyadmin' 将 'root' 替换为 'alias'https://nginx.ru/en/docs/http/ngx_http_core_module.html#alias来解决它。
例子:
location /phpmyadmin {
alias /usr/share/phpmyadmin;
index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_pass php-fpm;
}
答案2
我最终通过以下配置让它工作了;
server {
listen 80 default_server;
access_log /var/log/nginx/phpmyadmin_access.log;
error_log /var/log/nginx/phpmyadmin_error.log;
# Main application:
root /var/www/html;
index index.php index.html index.htm;
# phpMyAdmin:
location /phpmyadmin {
root /usr/share;
index index.php;
}
# PHP files for phpMyAdmin:
location ~ ^/phpmyadmin(.+\.php)$ {
root /usr/share;
index index.php;
#fastcgi_read_timeout 300;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
# PHP files for the main application:
location ~ \.php$ {
fastcgi_read_timeout 300;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
}
答案3
您应该检查以下几件事:
- 首先,检查尾部 /var/log/nginx/error.log
- 检查www-数据所有者phpMyAdmin 目录
- 在 nginx 配置中,检查位置 /phpmyadmin 是否位于位置 ~ .php$ 上方
- 注意大小写,phpMyAdmin 和 phpmyadmin 目录不一样
- 检查 fastcgi_pass unix:/run/php/php7.1-fpm.sock; - 您的服务器上是否安装了此 PHP-FPM 版本