ubuntu 16.04 nginx 更改 phpmyadmin url 不起作用 [英] ubuntu 16.04 nginx change phpmyadmin url not working

查看:52
本文介绍了ubuntu 16.04 nginx 更改 phpmyadmin url 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ubuntu 16.04.5 LTS Xenial 4.18.8-x86_64-linode117
nginx version: nginx/1.10.3 (Ubuntu)
php v7.0.32-0ubuntu0.16.04.1`

/etc/nginx/sites-available/default

location /phpmyadmin {
        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

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

/var/www/html处没有符号链接
很好....

No symlink at /var/www/html
Worx well....

但我似乎不知道如何更改 phpmyadmin 网址.
尝试在 /var/www/html 下创建符号链接 whatever ->/usr/share/phpmyadminwhatever ->/usr/share/phpmyadmin/不起作用,
即使我将 /etc/nginx/sites-available/default 更改为:

But I can't seem to figure out how to change phpmyadmin url.
Tried creating a symlink whatever ->/usr/share/phpmyadmin or whatever ->/usr/share/phpmyadmin/ under /var/www/htmldoes not work,
Even if I change /etc/nginx/sites-available/default to:

location /whatever {
        root /usr/share/phpmyadmin/;

如上所述创建一个符号链接,重新启动 nginx &php7.0-fpm 仍然是新的 URL 试图下载页面...

Created a symlink as mentioned above, restarted both nginx & php7.0-fpm still the new URL tried to download the page...

在网上查找了不同的资源,但没有帮助:
数字海洋指南
devanswers 指南
以及 SO 上的其他内容,但找不到解决方案.
想法??

Looked up different resources on the net but they dont help:
digitalocean's guide
devanswers guide
As well as other here on SO but couldn't find a solution.
Ideas??

更新
根据理查德·史密斯的评论

location /whatever {
    alias /usr/share/phpmyadmin;
    index index.php index.html index.htm;
    if (!-e $request_filename) { rewrite ^ /phpmyadmin/index.php last; }
    # Secure phpMyAdmin Instance
    auth_basic "Admin Login";
    auth_basic_user_file /etc/nginx/.your_pass_file;
    client_max_body_size 68M;

    location ~ ^/phpmyadmin/(.+\.php)$ {
        if (!-f $request_filename) { return 404; }
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME 
        $document_root$fastcgi_script_name;
    }

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

推荐答案

尝试:

location ^~ /whatever {
    alias /usr/share/phpmyadmin;
    index index.php index.html index.htm;
    if (!-e $request_filename) { rewrite ^ /whatever/index.php last; }
    # Secure phpMyAdmin Instance
    auth_basic "Admin Login";
    auth_basic_user_file /etc/nginx/.your_pass_file;
    client_max_body_size 68M;

    location ~ \.php$ {
        if (!-f $request_filename) { return 404; }
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

您需要在rewrite 语句中使用/whatever/index.php.嵌套的位置块只需要匹配 URI 的结尾.^~ 修饰符避免在 server 块级别与其他正则表达式 location 块发生冲突.在 SCRIPT_FILENAME 中使用 $request_filename.您最后一个嵌套的 location 块似乎不起作用.

You need to use /whatever/index.php in the rewrite statement. The nested location blocks only need to match the end of the URI. The ^~ modifier avoids conflicts with other regular expression location blocks at the server block level. Use $request_filename in the SCRIPT_FILENAME. Your last nested location block appears to perform no function.

由于 aliastry_files>这个问题.请参阅此注意事项关于的使用,如果.

Avoid try_files with alias due to this issue. See this caution on the use of if.

这篇关于ubuntu 16.04 nginx 更改 phpmyadmin url 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆