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.
map $upstream_http_content_type $expires2 { ... }
withexpires $expires2;
Expires
header for proxied content (added the code to my question).Content-Type
header usingcurl -I
. If it's likeContent-Type text/html; charset=utf-8
it will not match your map, and you may want to use a regex instead.Content-Type
header did contain the encoding, and changing the map entry to~text/html 2d;
solved my problem. Thank you!