404 / phpmyadmin与Nginx和Debian 8 jessie

时间:2018-04-23 14:58:02

标签: nginx debian

我找到了很多答案,但没有一个能解决我的问题:

我尝试访问/ phpmyadmin但是我使用Nginx 1.6.2,PHP7.0和Debian 8(Jessie)登陆404。

这是我的/etc/nginx/site-available/guillaume-rz.fr:

server {                                                                                 
    listen 80;                                                                       
    root /home/guillaume-rz/www;                                                     
    server_name www.guillaume-rz.fr;                                                 
    location / {                                                                     
            index index.php;                                                         
    }                                                                                

    location /phpmyadmin {                                                           
            root /usr/share/phpmyadmin;                                              
            index index.php index.html index.htm;                                    
            location ~ ^/phpmyadmin/(.+\.php)$ {                                     
                    try_files $uri =404;                                             
                    root /usr/share/;                                                
                    fastcgi_pass unix:/var/run/php7.0-fpm.sock; # or 127.0.0.1:9000  
                    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/;                                                
            }                                                                        
    }                                                                                

    location /phpMyAdmin {                                                           
             rewrite ^/* /phpmyadmin last;                                           
    }                                                                                

    location ~ \.php$ {                                                              
            include snippets/fastcgi-php.conf;                                       
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;                          
            # include /etc/nginx/fastcgi_params;                                     
            # fastcgi_index index.php;                                               
    }                                                                                
}       

我安装了PhpMyAdmin,可以在这里找到:/ var / www / phpmyadmin /

我创建了一个符号链接:ln -s / usr / share / phpmyadmin / / var / www / phpmyadmin

1 个答案:

答案 0 :(得分:2)

目前,您的PHP脚本正在由最后一个location块处理,即使它们以/phpmyadmin/开头。正则表达式location块优先于同一级别的前缀location块。有关详细信息,请参阅this document

使用^~修饰符更改优先顺序,例如:

location ^~ /phpmyadmin {                                                           
    root /usr/share;                                              
    index index.php index.html index.htm;                                    

    location ~ \.php$ {                                     
        try_files $uri =404;                                             
        fastcgi_pass unix:/var/run/php7.0-fpm.sock; # or 127.0.0.1:9000  

        include /etc/nginx/fastcgi_params;                               
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }                                                                            
}