I know how you can assign NGINX Expires headers by mime type (answered here). However, it's unclear how to use this method to assign different Expires headers per virtual host. For example, I might have the below in the http
context. Because map
directive needs to go into the http
context, map and $expires
will apply globally for all virtual hosts.
map $sent_http_content_type $expires {
~text/ -1;
default max;
}
Then I can add $expires
into http
(applied globally), server
or location
.
expires $expires;
What if I now want different expires for another website? I would need to create a new map to $website2
.
map $sent_http_content_type $website2 {
~application/ -1;
~text/ -1;
default max;
}
... and then assign this specifically for the virtual host where I want to use it.
server {
server_name mydomain.com;
...
expires $website2;
Now this does work, but now ALL requests for ALL virtual hosts will be mapping $sent_http_content_type
to multiple vars, even if each $var is only used for (and only intended for) a single virtual host. Isn't this very ineffective? Am I missing something?
Don't worry about many maps.
https://nginx.org/en/docs/http/ngx_http_map_module.html#map