NGINX 缓存 phpmyadmin – 图片未加载
Posted
技术标签:
【中文标题】NGINX 缓存 phpmyadmin – 图片未加载【英文标题】:NGINX caching phpmyadmin – images not loading 【发布时间】:2018-12-10 01:00:37 【问题描述】:我有一个 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】:在 Nginx 中,正则表达式匹配优于前缀匹配。所以这个指令被认为更适合任何以 gif 结尾的东西
location ~* \.(jpg|jpeg|png|gif|ico)$ expires 30d;
比这个
location /phpmyadmin
所以你的图片都被顶部位置指令处理,即使是开始 /phpmyadmin 的那些,第一个指令与你的 phpmyadmin 位置有不同的根目录,所以 Nginx 找不到那里的文件
【讨论】:
好的 - 这是处理顺序问题吗?有没有办法排除 phpmyadmin 目录不被该语句处理? 如果你把它放在 location 块之上并将它更改为^~ /phpmyadmin
那么 Nginx 将不会处理匹配这个前缀的请求的正则表达式指令以上是关于NGINX 缓存 phpmyadmin – 图片未加载的主要内容,如果未能解决你的问题,请参考以下文章
phpMyAdmin 显示 404 未找到(Ubuntu 18.04 Nginx)
phpmyadmin 的布局在 ubuntu nginx 服务器中变得凌乱