Nginx中Location的非匹配正则写法

Published: Tags: NGINX

最近发现项目中有部分静态文件没有被客户端缓存,是由于location中没加上对应后缀, 因此应该对所有文件进行强缓存的设置,再反过来对几个动态的后缀进行匹配会更简单:

server {
    listen       80;
    server_name  test.jiangjun.vip;

    root /zone/www/test;

    location / {
        index index.php index.html;
    }

    location ~* \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi_params;
    }

    # 注意写法和顺序,会影响能否正确匹配
    location ~* \.(?!(php|jsp|asp|aspx)$) {
        expires 3650d;
        add_header Cache-Control "max-age=315360000";
    }
}