AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 433785
Accepted
Frederik
Frederik
Asked: 2012-10-02 11:54:44 +0800 CST2012-10-02 11:54:44 +0800 CST 2012-10-02 11:54:44 +0800 CST

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

  • 772

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

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

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

nginx
  • 8 8 个回答
  • 21844 Views

8 个回答

  • Voted
  1. Daniel Alves
    2016-07-25T20:26:10+08:002016-07-25T20:26:10+08:00

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

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

    如链接所述: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;
       }
    

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

    • 13
  2. Saúl Delgadillo R
    2016-07-05T17:52:51+08:002016-07-05T17:52:51+08:00

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

    • 4
  3. Mikec
    2012-10-03T02:38:42+08:002012-10-03T02:38:42+08:00

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

    如果通过阅读并改变你的配置你仍然有问题请告诉!

    • 2
  4. Best Answer
    Michael Hampton
    2012-10-03T12:23:43+08:002012-10-03T12:23:43+08:00

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

    • 2
  5. MOHAMMAD026
    2017-01-16T15:34:31+08:002017-01-16T15:34:31+08:00

    打开:

    /var/lib/phpMyAdmin/config.inc.php
    

    添加:

    $cfg['PmaAbsoluteUri'] = 'https://www.example.net/path_to_your_phpMyAdmin_directory/';
    

    请参阅:
    https ://docs.phpmyadmin.net/en/latest/config.html#basic-settings

    .

    • 1
  6. Sandeep Kumar Soni
    2016-08-30T22:55:31+08:002016-08-30T22:55:31+08:00

    使用任何域名(例如 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

    • 0
  7. Simon Fearby
    2016-10-22T04:18:52+08:002016-10-22T04:18:52+08:00

    只有这个对我有用

    location /utils/phpmyadmin/ {
        try_files $uri $uri/ =404;
        index index.php index.html index.htm
        proxy_set_header Proxy "";
    }
    
    • 0
  8. Rampages
    2017-03-17T19:56:19+08:002017-03-17T19:56:19+08:00

    来自 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#';
    

    在浏览器中保存并打开您的域/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;
    

    现在尝试在浏览器中打开域/任何东西

    • -1

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve