NGINX缓存phpmyadmin –无法加载图片

时间:2018-07-01 17:09:47

标签: nginx caching phpmyadmin compression

我有一台NGINX服务器,其中已为laravel网站启用缓存。我在服务器上也有phpmyadmin。由于启用了缓存,因此查看时phpmyadmin的所有图像均不会返回。在下面,请找到服务器代码。谢谢您的帮助。

/phpmyadmin/themes/dot.gif 404(未找到)

NGINX配置

server {
if ($host = www.xx.com) {        return 301 https://$host$request_uri;    } 
if ($host = xx.com) {        return 301 https://$host$request_uri;    } 



listen 80;
listen [::]:80;
server_name xx.com www.xx.com;
return 301 https://$host$request_uri;
}

server {

listen 443 ssl default_server;
listen [::]:443 ssl default_server;

root /var/www/yyyy;

gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/xml+rss;
#css|js
location ~*  \.(jpg|jpeg|png|gif|ico)$ {        expires 30d;    }
location ~*  \.(pdf)$ {        expires 30d;    }

ssl_certificate /xxx/fullchain.pem; # managed by x
ssl_certificate_key /xxx/privkey.pem; # managed by xx

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "xxx";
ssl_session_cache shared:SSL:10m;

ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_session_timeout 1d;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;


index index.php index.html index.htm;

server_name xx.com www.xx.com;

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

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
    deny all;
}

location /phpmyadmin {
    root /usr/share/;
    index index.php;
    try_files $uri $uri/ =404;                                          

    location ~ ^/phpmyadmin/(doc|sql|setup)/ {
        deny all;
    }

    location ~ /phpmyadmin/(.+\.php)$ {

        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        include snippets/fastcgi-php.conf;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 4k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_read_timeout 240;

    }

}

}

1 个答案:

答案 0 :(得分:1)

在Nginx regex匹配中胜过前缀匹配。因此,该指令被认为是所有以gif等结尾的匹配项

location ~* \.(jpg|jpeg|png|gif|ico)$ { expires 30d; }

比这个

location /phpmyadmin {

因此,所有图像均由to​​p location指令处理,即使是以/ phpmyadmin开头的图像,第一个指令的根目录也与phpmyadmin位置不同,因此Nginx在此处找不到文件