Nginx phpmyadmin 在登录时重定向到 / 而不是 /phpmyadmin

Fre*_*sen 9 configuration nginx

我在安装 nginx 时遇到了 phpmyadmin 的问题。

当我进入<ServerIP>/phpmyadmin并登录时,我被重定向到<ServerIP>/index.php?<tokenstuff>而不是<ServerIP>/phpmyadmin/index.php?<tokenstuff>

Nginx 配置文件:

user  nginx;
worker_processes  5;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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  2;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
Run Code Online (Sandbox Code Playgroud)

默认.conf:

server {
    listen       80;
    server_name  _;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
    location /phpmyadmin {
    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
        try_files $uri =404;
        root /usr/share/;
        fastcgi_pass unix:/tmp/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_script_name;
    }

    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
        root /usr/share/;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

(任何关于整理这些配置文件的一般提示也被接受)

小智 13

尽管作者已经解决了重新安装 phpMyAdmin 的问题,但需要正确配置 nginx 以正确处理登录时的重定向。

经过几天在键盘上砸我的头,我终于找到了真正的解决方案,我在这里分享,因为该线程在谷歌搜索上仍然具有很高的优先级。

如链接所述:http : //www.samundra.com.np/use-phpmyadmin-with-nginx-and-php7/1374

要解决该问题,您应该将以下代码块添加到您的 nginx 默认站点可用中,您将使用以下命令访问它:

sudo nano /etc/nginx/sites-available/default
Run Code Online (Sandbox Code Playgroud)

将此块放在server块中:

# Phpmyadmin Configurations
    location /phpmyadmin {
       root /usr/share/;
       index index.php index.html index.htm;
       location ~ ^/phpmyadmin/(.+\.php)$ {
               try_files $uri =404;
               root /usr/share/;
               #fastcgi_pass 127.0.0.1:9000;
               #fastcgi_param HTTPS on; # <-- add this line
               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;
       }
       location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
               root /usr/share/;
       }
   }

   # Dealing with the uppercased letters
   location /phpMyAdmin {
       rewrite ^/* /phpmyadmin last;
   }
Run Code Online (Sandbox Code Playgroud)

我希望有一天这可以帮助某人...


Mic*_*ton 2

这听起来不像是 nginx 的问题。这听起来像是 phpMyAdmin 没有正确安装,并认为它位于/而不是/phpmyadmin。检查您的 phpMyAdmin 配置。

  • “只需重新安装”是一个荒谬的答案。如果phpMyAdmin的配置错误,应该有一种方法可以重新配置,而不必重新安装整个应用程序! (4认同)