Nginx更改/ phpmyadmin目录

时间:2013-06-28 07:25:02

标签: nginx phpmyadmin

我想让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)

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

2 个答案:

答案 0 :(得分:4)

在Ubuntu服务器上,我使用以下设置在/pma下为几个Nginx站点提供phpMyAdmin。

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

答案 1 :(得分: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;
    }
}

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

client_header_timeout 0;
client_max_body_size 64m; #change this if ur export is bigger than 64mb.
client_body_buffer_size 128k;