Laravel 路由用 nginx 覆盖 phpmyadmin 路径

Laravel routes overwriting phpmyadmin path with nginx

我的 LEMP droplet 上有以下 nginx 配置:

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 和 Laravel on/phpmyadmin 但只有 Laravel 路由被提供给浏览器。因此,任何 /phpmyadmin 都将被解析为不是路由的路由。

我试过很多东西

我很确定这可能是我遗漏的一件小事。

假设你的phpmyadmin配置文件是/etc/phpmyadmin/nginx-php5-fpm.conf

尝试在 location{}:

之前将其添加到您的 nginx 配置中
include /etc/phpmyadmin/nginx-php5-fpm.conf;

将此添加到您的 phpmyadmin.conf

location /pma {
    alias /usr/share/phpmyadmin/;
}

location ~ ^/pma/(.*\.(js|css|gif|jpg|png))$ {
    alias /usr/share/phpmyadmin/;
}

location ~ ^/pma(.+\.php)$ {
    alias /usr/share/phpmyadmin;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;

    charset utf8;

    include fastcgi_params;
    fastcgi_param DOCUMENT_ROOT /usr/share/phpmyadmin;
}

您的 phpmyadmin 可以通过 http://yourdomain/pma

访问

尽情享受吧!

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

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

只需确保将三个 "root" 位置调整到您的 "phpmyadmin" 文件夹所在的文件夹(我的 phpmyadmin 文件夹的位置在这里:“/usr/share/nginx/html/phpmyadmin"