nginx + fast-cgi - 如何使phpmyadmin工作

时间:2013-05-13 21:23:12

标签: nginx phpmyadmin fastcgi

我配置了我的nginx服务器+ php。除了phpmyadmin,Eeverything工作正常。

我搜索了很多并发现了一些别名技巧,但它们对我不起作用。

这很有效:

        location ~ ^/ololo/(.*\.php)$ {
                alias $root_path/img/$1;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include /etc/nginx/fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $request_filename;
        }

        location /ololo/ {
                alias $root_path/img/;
                index index.php;
        }

我的网站路径中有img目录,当我请求sitename/ololo/sitename/ololo/index.php时,一切都很好。

但那:

         location ~ ^/myadmin/(.*\.php)$ {
                alias /usr/share/phpmyadmin/$1;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $request_filename;

        }

        location /myadmin/ {
                alias /usr/share/phpmyadmin/;
                index index.php;
        }

不起作用!

当我尝试请求mysite/myadmin/mysite/myadmin/index.php服务器抛出我

  

未指定输入文件。

错误消息。在/usr/share/phpmyadmin/中都是.php个文件。

我的nginx.conf出了什么问题?

3 个答案:

答案 0 :(得分:2)

好的,根据我在回复中的理解,我正在修改这个答案,将其添加到您的主服务器,它应该可以工作。

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

修改

好的,所以一个下载的vode让我再看看这个,已经有一段时间了,因为我写了这个答案,我应该说这不是我如何编写配置文件,如果今天,这里是我将使用的配置。

location /phpmyadmin {
    index index.php index.htm;
    root /usr/share;
}

location ~* \.php$ {
    include fastcgi_params;
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
}

如果您想使用别名,请用此

替换phpmyadmin
location /phpmyadmin {
    index index.php index.htm;
    alias /usr/share/phpmyadmin;
}

注意:如果您的服务器块已包含index,则无需在phpmyadmin块内重新定义它。

答案 1 :(得分:0)

读取注释顺序必须准确,如果仍然错误,请阅读error.log

### first define phpmyadmin static files
location ~ ^/phpmyadmin/.*\.(jpg|jpeg|gif|png|ico|css|js|woff|ttf)$ {
        root /usr/share/;
        expires max;
        #log_not_found off;
}

### then your public_html static file   
location ~* \.(jpg|jpeg|gif|png|ico|css|js|woff|ttf)$ {
        root /path/public_html;
        expires max;
        #log_not_found off;
}

因为phpmyadmin路径在public_html之外,所以你需要try_files将斜线“/”重定向到“/ index.php”

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

现在是最后一个,fastcgi

### Define phpmyadmin PHP files
location ~ ^/phpmyadmin/(.*)\.php$ {
    ## optional, try uncomment if error
    #root /usr/share/phpmyadmin/;

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/$fastcgi_script_name;
    include fastcgi_params;
}

### then your public_html files 
location ~ \.php$ {
    ##optional, try uncomment if error
    #root           /path/public_html;

    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /path/public_html/$fastcgi_script_name;
    include        fastcgi_params;
}

现在您可以在http://yoursite/phpmyadmin

上访问phpmyadmin了

答案 2 :(得分:0)

这是我的配置:

location /phpmyadmin {
    alias   /usr/share/phpmyadmin;
    index index.php;
    location ~ /([^/]+\.php)$ {
        try_files /$1 =404;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        location ~ /phpmyadmin/js/([^/]+\.php)$ {
            try_files /phpmyadmin/js/$1 =404;
            fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
}