Laravel routes overwriting phpmyadmin path with ng

2019-07-23 04:51发布

问题:

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

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.

I have tried multiple things

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

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

  • 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.

回答1:

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

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"



回答2:

Assuming your phpmyadmin configuration file is /etc/phpmyadmin/nginx-php5-fpm.conf

Try adding this to your nginx config before location{}:

include /etc/phpmyadmin/nginx-php5-fpm.conf;

add this into your phpmyadmin.conf

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

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

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

    charset utf8;

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

Your phpmyadmin will be accessible through http://yourdomain/pma

Enjoy !