Nginx + phpMyAdmin问题

时间:2014-07-04 03:36:51

标签: nginx phpmyadmin

我的Nginx配置文件存在问题。当我加载phpMyAdmin时,一切正常 - 除了图像不会加载。

检查错误日志,我发现对图像/其他静态内容的所有请求都在请求结束时添加了“/index.php”。

如果有人能让我知道我做错了什么,我将不胜感激。

错误日志:

2014/07/03 20:17:32 [error] 75683#0: *61 "/local/www/phpMyAdmin/themes/original/img/ajax_clock_small.gif/index.php" is not found
2014/07/03 20:17:33 [error] 75683#0: *59 "/local/www/phpMyAdmin/themes/original/jquery/jquery-ui-1.9.2.custom.css/index.php" is not found
2014/07/03 20:17:33 [error] 75683#0: *61 "/local/www/phpMyAdmin/themes/original/img/logo_left.png/index.php" is not found
2014/07/03 20:17:33 [error] 75683#0: *58 "/local/www/phpMyAdmin/themes/original/img/ajax_clock_small.gif/index.php" is not found

Nginx配置:

server {

    listen  XX.XX.XX.XXX:443;

    ssl on;
    ssl_certificate        /etc/ssl/cert/example.com/example.com.crt; 
    ssl_certificate_key    /etc/ssl/cert/example.com/example.com.key;

    server_name     example.com;
    access_log      off;
    error_log       /var/log/nginx/example_error.log;

    root            /opt/www/example.com/httpdocs;
    index           index.php index.html;

    charset UTF-8;

    try_files $uri $uri/ @backend;

    location  /phpmyadm/ {
       alias               /local/www/phpMyAdmin/;
    }

    location ~* ^/phpmyadm/(.+\.(jpg|jpeg|gif|png|bmp|ico|pdf|flv|swf|html|htm|txt|css|js))$ {
       alias              /local/www/phpMyAdmin/;
       expires            365d;
       etag               on;
    }

    # Pass off php requests to Apache
    location ~* \.php {
       include            /etc/nginx/proxypass.conf;
       proxy_pass         http://127.0.0.1:80;
    }

    location @backend {
       include            /etc/nginx/proxypass.conf;
       proxy_pass         http://127.0.0.1:80;
    }
}

2 个答案:

答案 0 :(得分:1)

为php和像这个例子中的资产创建类似/ phpmyadmin_secure的定位

#### PHPMYADMIN
    location /phpmyadmin_secure {
        index index.php;
        location ~ ^/phpmyadmin_secure/(.+\.php)$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
        location ~ \.(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                root    /usr/share/phpmyadmin;
         }
    }
####

答案 1 :(得分:0)

使用alias代替root并避免使用try_files对我来说非常有用:

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

    if (!-e $request_filename) { rewrite ^ /secure_phpmyadmin/index.php last; }

    location ~ \.php$ {

        if (!-f $request_filename) { return 404; }

        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

由于this issue,请避免将try_filesalias一起使用。关于if的使用,请参见this caution