My setup uses a map to define different Expires
headers for various static files (based on their mime type). For proxied content (uwsgi_pass
), I use a static Expires
header:
map $sent_http_content_type $expires {
default off;
text/html 7d;
text/css 180d;
application/font-woff2 1y;
application/pdf 1y;
~image/ 1y;
}
server {
listen 443 ssl http2;
server_name example.com;
location / {
uwsgi_pass django;
expires 7d;
}
location ~ ^/(css|fonts|images|pdf|html)/ {
root /var/www/django/static/;
expires $expires;
}
}
Using the map (via the $expires
variable) for proxied content does not work. Is there any way for nginx to identify the mime type of proxied content in order to make this work?
location / {
uwsgi_pass django;
expires $expires;
}
(Edit) As Alexey suggested, I did this:
map $upstream_http_content_type $expires2 {
default off;
text/html 2d;
text/plain 20d;
text/css 180d;
}
location / {
uwsgi_pass django;
expires $expires2;
}
Unfortunately, there is still no Expires
header added to the content delivered via uwsgi.
The solution was provided by Alexey and Richard in the comments. I had to use a different nginx variable, and a regex for (at least) the map entry for HTML files: