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


9

我在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;
}

Default.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/;
    }
}
}

(任何整理这些配置文件的常规技巧也被接受)


@MichaelHampton实际上,我认为这是问题所在。我删除了通过yum安装的软件包,并从phpmyadmin网站和voilá下载了最新的软件包。如果您提出答案,我会接受的。
弗雷德里克·尼尔森

Answers:


2

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


这就是导致我找到正确答案的原因-重新安装phpmyadmin-谢谢!:)
弗雷德里克·尼尔森

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

1
希望获得更多信息:请链接到说明如何以及在何处设置“ PHP认为它在哪里”参数的源。
戴安娜

这更多是评论,而不是答案。很好的建议,但是,请检查phpMyAdmin呢?
SherylHohman '18

@SherylHohman可能会单独提出一个有趣的问题。但是这个问题早就解决了。
迈克尔·汉普顿

13

即使作者解决了重新安装phpMyAdmin的问题,但仍需要正确配置nginx才能正确登录后处理重定向。

经过几天的努力,我终于找到了真正的解决方案,并且在这里分享了我的想法,因为该主题在Google搜索中仍然具有较高的优先级。

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

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

sudo nano /etc/nginx/sites-available/default

将此块放在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;
   }

我希望有一天能对某人有所帮助...


很高兴这解决了您的问题!祝您编码愉快!
Daniel Alves

就在这里...解决所有问题...
ThatTechGuy

肯定为我节省了超过一天的时间。投票!
徐吟

不为我修复它。还有其他想法吗?
戴安娜(Diana)2016年

如果我不希望在/ phpmyadmin处使用phpmyadmin,而在/ whatever处却要怎么办?我尝试更改嵌套的“位置”,但是没有用。
0lli.rocks,

4

此问题是由cgi.fix_pathinfo = 0的通用配置引起的,该配置禁用了PHP-FPM的当前路径。一种快速的解决方案是将cgi.fix_pathinfo更改回1,或在nginx的虚拟服务器块上设置路径参数。


2

您的问题似乎与此类似:https : //stackoverflow.com/questions/1011101/nginx-location-directive-doesnt-seem-to-be-working-am-i-missing-something

如果通过阅读和更改您的配置仍然有问题,请告知!


我读的线程,并尝试一些CONFIGS,但还是同样的问题-要么被重定向到/而不是/ phpMyAdmin的,或者只是去404
弗雷德里克·尼尔森

404是由“ try_files”“生成”的,这意味着它找不到phpmyadmin文件...也许phpmyamdin安装出错了?
Mikec 2012年

只要注意其他评论-.-我想毕竟是phpmyadmin config!
Mikec,2012年

可能是..我认为这是两者的结合。
弗雷德里克·尼尔森


0

使用任何域名将virtaul主机添加到您的Lamp服务器,例如phpmyadmin1.com

server {
    #listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;

    root /var/www/phpmyadmin;
    #some /var/www/html/phpmyadmin
    index index.php index.html index.htm;

    server_name phpmyadmin1.com;

        location / {
        try_files $uri $uri/ /index.php?$args;
     }

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

编辑您的主机文件

在底部添加此行

192.168.1.xx  phpmyadmin1.com

保存并关闭,然后重新启动服务器

service nginx restart

service php5-fpm restart

在浏览器上访问您的虚拟主机URL,请参见phpmyadmin登录页面

http://screencloud.net/v/nGK5

http://screencloud.net/v/6M8r


欢迎来到服务器故障!在这两个您的问题和答案请尝试使用随机域名和使用您的任何克制自己的域名或一个RFC 6761保留的域名,例如 example.comexample.org 或者类似的。请参考此问答,以获取有关如何混淆问题以及避免混淆问题的建议。
HBruijn

0

只有这个对我有用

location /utils/phpmyadmin/ {
    try_files $uri $uri/ =404;
    index index.php index.html index.htm
    proxy_set_header Proxy "";
}

-1

来自Ubuntu 16.04和更高版本存储库的phpMyAdmin无法正确重定向。

我只是从官方phpmyadmin网站下载新版本的phpmyadmin:

sudo wget https://files.phpmyadmin.net/phpMyAdmin/4.6.6/phpMyAdmin-4.6.6-all-languages.tar.gz

sudo tar xvf phpMyAdmin-4.6.6-all-languages.tar.gz

sudo mv phpMyAdmin-4.6.6-all-languages /usr/share/phpmyadmin

sudo rm -rf phpMyAdmin-4.6.6-all-languages.tar.gz

sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php

打开config.inc.php:

sudo nano /usr/share/phpmyadmin/config.inc.php

并在“

$cfg['blowfish_secret'] = 'i\kywQ>_h4L~S-Pt2rS'VAe)QpED7JI#';

保存并在浏览器中打开您的domain / phpmyadmin

您也可以将链接更改为phpmyadmin(以提高安全性),并从nginx添加基本身份验证以链接:

sudo ln -s /usr/share/phpmyadmin /var/www/html

cd /var/www/html

sudo mv phpmyadmin anything

现在您的phpmyadmin在https:// domain / anything上工作,让我们添加一些密码:

sudo sh -c "echo -n 'YourNameForLoginThere:' >> /etc/nginx/pmapass"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/pmapass"

现在打开您的nginx配置(默认情况下:sudo nano / etc / nginx / sites-available / default)并添加befor last}

location /anything {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/pmapass;
}

启用配置存储:

sudo nano /usr/share/phpmyadmin/config.inc.php

找到以下几行:

// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';

改成:

$cfg['Servers'][$i]['controluser'] = 'yourdatabaseuser';
$cfg['Servers'][$i]['controlpass'] = 'yourdatabasepassword';

定位:

// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
// $cfg['Servers'][$i]['relation'] = 'pma__relation';
// $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
// $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
// $cfg['Servers'][$i]['history'] = 'pma__history';
// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
// $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
// $cfg['Servers'][$i]['recent'] = 'pma__recent';
// $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
// $cfg['Servers'][$i]['users'] = 'pma__users';
// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

取消注释(删除//

现在保存并退出。

转到您的mysql(默认情况下:sudo mysql -u root -p

GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'yourdatabaseuser'@'localhost' IDENTIFIED BY 'yourdatabasepassword';
exit;

现在尝试在浏览器中打开域/任何内容

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.