3

我已经配置了我的 nginx 服务器 + php。一切正常,除了 phpmyadmin。

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

这很好用:

        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

4

3 回答 3

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

编辑

好的,所以一个失败的投票让我再次看了一下这个,我已经有一段时间没有写这个答案了,我应该说这不是我今天写配置文件的方式,这是配置我会用。

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块内重新定义它。

于 2013-05-13T22:55:46.427 回答
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;
}

因为public_html之外的phpmyadmin路径所以你需要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;
}

现在您可以访问 phpmyadminhttp://yoursite/phpmyadmin

于 2014-01-29T20:17:05.203 回答
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;
        }
    }
}
于 2016-07-14T07:56:41.803 回答