首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx重写不工作(Kirby CMS Cachebuster)

Nginx重写不工作(Kirby CMS Cachebuster)
EN

Stack Overflow用户
提问于 2015-12-02 07:30:49
回答 1查看 757关注 0票数 1

Nginx将/assets/css/main.1448958665.css重写为/assets/css/main.css。但试图获取该文件时,它会返回一个404

这是我的Nginx站点配置:

代码语言:javascript
复制
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插件,如果这确实有帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-02 16:11:05

这个问题与nginx如何处理请求有关。您的location ~* \.(svg|js|css|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot)$优先于location /assets

一个简单的修正(假设它不包含php)是将其优先级移动到regex之上,方法是将其写入如下:

代码语言:javascript
复制
location ^~ /assets { ... }

在这种情况下,您可能还想向容器添加一个expires指令。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34037122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档