Nginx将/assets/css/main.1448958665.css重写为/assets/css/main.css。但试图获取该文件时,它会返回一个404。
这是我的Nginx站点配置:
server {
listen 80 default_server;
server_name example.com;
root /var/www/example.com;
index index.php index.html index.htm;
client_max_body_size 10M;
rewrite ^/(content|site|kirby)$ /error last;
rewrite ^/content/(.*).(txt|md|mdown)$ /error last;
rewrite ^/(site|kirby)/(.*)$ /error last;
location /assets {
if (!-e $request_filename) {
rewrite ^/(.+)\.(\d+)\.(js|css)$ /$1.$3 break;
}
}
location / {
try_files $uri $uri/ /index.php?$uri&$args;
}
location /panel {
try_files $uri $uri/ /panel/index.php?$uri&$args;
}
location ~ (?:^|/)\. {
deny all;
}
location ~ (?:\.(?:bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$ {
deny all;
}
location ~* \.(svg|js|css|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot)$ {
expires 1y;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
}
}我正在使用柯比CMS与Cachebuster插件,如果这确实有帮助。
发布于 2015-12-02 16:11:05
这个问题与nginx如何处理请求有关。您的location ~* \.(svg|js|css|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot)$优先于location /assets。
一个简单的修正(假设它不包含php)是将其优先级移动到regex之上,方法是将其写入如下:
location ^~ /assets { ... }在这种情况下,您可能还想向容器添加一个expires指令。
https://stackoverflow.com/questions/34037122
复制相似问题