Nginx with phpmyadmin wrong redirect after login

前端 未结 6 1582
时光取名叫无心
时光取名叫无心 2021-02-04 13:48

I\'m setting up phpMyAdmin with nginx. I can visit phpMyAdmin at http://localhost/phpmyadmin. However, when I logged in, the URL is redirected to http://localhost/sql.php instea

6条回答
  •  一个人的身影
    2021-02-04 14:41

    I have actually been through so many solutions on StackOverflow today and sadly none of which work and some even given some horrid recommendations. What's scary is how many I came across that were marked as answers.

    I just did a brand new Ubuntu 16.04 LEMP server, everything cleanly installed this morning Nginx, mySQL, PHP7.0 and PhpMyAdmin.

    This problem of redirecting to

    h**p://my.server.ip/

    after logging into phpymadmin instead of

    h**p://my.server.ip/phpmyadmin

    is nothing actually to do with the cgi.fix_pathinfo being set to 0 as recommended by all those guides you read. Read up a little more on why it should be set to 0 in your php.ini file and don't just go and disable it as above.

    So in other words leave (as recommended to you) cgi.fix_pathinfo = 0 in your config file for PHP.

    THE FIX from this web site (the only one with the correct answer) is to add the following to your /etc/nginx/sites-available/default configuration file. Then restart Nginx ... works immediately, no more re-directing back to root after login.

    # 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 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/;
           }
       }
    
       location /phpMyAdmin {
           rewrite ^/* /phpmyadmin last;
       }
    

提交回复
热议问题