Nginx 重写不工作(Kirby CMS Cachebuster)
Nginx rewrite not working (Kirby CMS Cachebuster)
Nginx 应将 /assets/css/main.1448958665.css
重写为 /assets/css/main.css
。但是试图获取该文件,它 returns a 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)$ /. 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;
}
}
如果有帮助的话,我正在使用带有 Cachebuster 插件的 Kirby CMS。
问题与 how nginx processes a request 有关。您的 location ~* \.(svg|js|css|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot)$
优先于 location /assets
。
一个简单的修复(假设它不包含 php)是将其优先级写为:
location ^~ /assets { ... }
在这种情况下,您可能还想向容器添加一个 expires
指令。
Nginx 应将 /assets/css/main.1448958665.css
重写为 /assets/css/main.css
。但是试图获取该文件,它 returns a 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)$ /. 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;
}
}
如果有帮助的话,我正在使用带有 Cachebuster 插件的 Kirby CMS。
问题与 how nginx processes a request 有关。您的 location ~* \.(svg|js|css|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot)$
优先于 location /assets
。
一个简单的修复(假设它不包含 php)是将其优先级写为:
location ^~ /assets { ... }
在这种情况下,您可能还想向容器添加一个 expires
指令。