Laravel使用Nginx路由覆盖phpmyadmin路径 [英] Laravel routes overwriting phpmyadmin path with nginx

查看:160
本文介绍了Laravel使用Nginx路由覆盖phpmyadmin路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的LEMP小滴上具有以下nginx配置:

I have the following nginx config on my LEMP droplet:

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

    root /var/www/html/public;
    index index.php index.html index.htm;

    server_name server_domain_or_IP;

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

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

我想在/phpmyadmin上将PHPMyAdmin与Laravel一起运行,但是只有Laravel路由会提供给浏览器.因此,任何/phpmyadmin都将被解析为一条不存在的路由.

I would like to run PHPMyAdmin together with Laravel on/phpmyadmin but only the Laravel routes get served to the browser. So any /phpmyadmin would be parsed as a route where it isn't one.

我尝试了多件事

  • 甚至在尝试使用^~ /phpmyadmin强制优先级时,在location ~ \.php上方添加我自己的位置/phpmyadmin.

  • Adding my own location /phpmyadmin above the location ~ \.php even trying ^~ /phpmyadmin to force precedence.

我将我的根目录设置为/usr/share/phpmyadmin,没有任何结果.

I've set my root to /usr/share/phpmyadmin, without any results.

我尝试复制fastcgi选项并基本上复制了完整的逻辑,但是使用/phpmyadmin也没有任何结果

I have tried copying the fastcgi options and basically copying the complete logic but using /phpmyadmin without any result either

我很确定这可能是我所缺少的小东西.

I am pretty sure it's probably a small thing that I am missing.

推荐答案

以下代码对我有用(添加在"location ~ \.php$ {"部分之前:

The following code worked for me (added before the "location ~ \.php$ {"-part:

location /phpmyadmin {
            root /usr/share/nginx/html;
            location ~ ^/phpmyadmin/(.+\.php)$ {
                    try_files $uri =404;
                    root /usr/share/nginx/html;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include /etc/nginx/fastcgi_params;
            }
            location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                    root /usr/share/nginx/html;
            }
    }

只需确保将三个根"位置调整到"phpmyadmin"文件夹所在的文件夹(我的phpmyadmin文件夹的位置在此处:"/usr/share/nginx/html/phpmyadmin "

Just make sure to adjust the three "root" locations to the folder where your "phpmyadmin" folder is in (the location of my phpmyadmin folder is here: "/usr/share/nginx/html/phpmyadmin"

这篇关于Laravel使用Nginx路由覆盖phpmyadmin路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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