4

我试图让 example.com/phpmyadmin 从我的站点路由到不同的目录,这样我就可以为我的所有站点使用一个通用的 phpmyadmin 安装。我试过这个:

server {
    listen      80;
    server_name example.com;

    location / {
        root    /home/web/example.com/public_html;
        index   index.html index.htm index.php;
    }

    location ~ \.php$ {
        root /home/web/example.com/public_html;
        if ($request_uri ~* /phpmyadmin) {
            root /home/web/phpmyadmin;
        }
        try_files $uri =404;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

这似乎根本不起作用。

我也试过这个:

server {
    listen      80;
    server_name example.com;

    location / {
        root    /home/web/example.com/public_html;
        index   index.html index.htm index.php;
    }

    location /phpmyadmin {
        root    /home/web/phpmyadmin;
        index   index.html index.htm index.php;
    }

    location ~ \.php$ {
        root /home/web/example.com/public_html;
        try_files $uri =404;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

当我用这个文件检查我的错误日志后,我得到:

2013/06/28 01:10:47 [error] 7068#0: *1 "/home/web/phpmyadmin/phpmyadmin/index.html" is not found (2: No such file or directory)

因此,在 location 块中,我将 root 更改为 /home/web,认为它会删除额外的 phpmyadmin,但是,相反,我在错误日志中根本没有得到任何关于 phpmyadmin 的信息。我似乎无法弄清楚正确的配置以及为什么这个配置不起作用。有任何想法吗?

4

2 回答 2

4

在 Ubuntu 服务器上,我使用以下设置使 phpMyAdmin 可/pma用于多个 Nginx 站点。

/etc/phpmyadmin/nginx-php5-fpm.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/php-fpm.sock;
    fastcgi_index index.php;

    charset utf8;

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

然后在任何/etc/nginx/sites-available/*我都可以使用这一行启用 pma 支持:

include /etc/phpmyadmin/nginx-php5-fpm.conf;
于 2013-06-29T08:08:50.153 回答
1

我认为您在第二个配置中的问题是index内部/phpmyadmin将其替换为index index.php

这是我服务器的 phpmyadmin,但它被配置为子域。

server {
    client_header_timeout 0;
    server_name phpmyadmin.example.com;
    root /var/www/phpmyadmin/;
    #replace this with your phpmyadmin location
    #like /usr/share/phpmyadmin for example
    index           index.php;
    access_log /var/log/nginx/phpmyadmin_access_log;
    error_log /var/log/nginx/phpmyadmin_error_log;
    location ~* \.php$ {
        try_files $uri =404;
        fastcgi_index   index.php;
        fastcgi_pass    unix:/var/run/php5-fpm.sock;
        include         fastcgi_params;
        client_max_body_size 64m;
        client_body_buffer_size 128k;
    }
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
        access_log        off;
        log_not_found     off;
        expires           360d;
    }
    location ~ /\.  {
        access_log off;
        log_not_found off;
        deny all;
    }
}

这三个设置用于导出和导入大文件,当导出的文件大于一定数量时,或者服务器需要时间生成导出的 sql 文件时,nginx 会失败。

client_header_timeout 0;
client_max_body_size 64m; #change this if ur export is bigger than 64mb.
client_body_buffer_size 128k;
于 2013-06-28T09:08:12.233 回答