1

I would like to alias all js,css to cache static, but not working. Do you know how to do this ?

    location ~* ^/(.*)/[^/].+.(css|js)$ {
    error_log /var/log/nginx/CssJs-log;
    alias /home/static/$1.$2;
    expires 30d;
    add_header X_Cached 1;
    error_page 403 404 502 504 = @SHtomcat;
}

1 Answer 1

1

Alias with a regex location must use capture groups to specify where the ressource should be served on the filesystem.

So basically here you are trying to resolve URI /foo/file.extension to the physical path /home/static/foo.extension which seems incorrect.

I believe you instead need to resolve this to /home/static/file.extension so use the following :

location ~* ^/.*/([^/].+.(css|js))$ {
    error_log /var/log/nginx/CssJs-log;
    alias /home/static/$1;
    expires 30d;
    add_header X_Cached 1;
    error_page 403 404 502 504 = @SHtomcat;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.