Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!




add_header Cache-Control "public, max-age=315360000"; location ~* "^/api/image/exif/(.*?)\.txt$" {
default_type text/plain;
set $testimageid $1;
##backend
if ($testimageid ~ 1337){
add_header Cache-Control "private, max-age=0" always;
return 404 "Image $testimageid not found";
}
return 200 "EXIF for $testimageid image";
##backend
}
add_header Cache-Control "private, max-age=0" always;, так как nginx по умолчанию не хедеры с 4хх ответами. location ~* "^/api/image/jexif/(.*?)\.txt$" {
##backend
proxy_pass http://localhost:8080/headerstest/headerstest.jsp?imgid=$1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
##backend
}
<%@ page contentType="text/plain;charset=UTF-8" language="java" trimDirectiveWhitespaces="true" session="false" %>
<%
String imgId = request.getParameter("imgid");
if (imgId != null){
if(imgId.equalsIgnoreCase("1337")) {
response.setStatus(404);
response.setHeader("Cache-Control", "private, max-age=0");
out.print("file not found");
}else{
out.print("Exif for image "+imgId);
}
}
%>
add_header Cache-Control "public, max-age=315360000"; из директивы server, и оставить только в location: location / {
add_header Cache-Control "public, max-age=315360000";
}
response.setHeader("Cache-Control", "public, max-age=20");
location ~* "^/api/image/exif/(?P<testimageid>.*?)\.txt$" {
default_type text/plain;
##backend
if ($testimageid ~ 1337){
return 418 "Image $testimageid not found";
}
##backend
return 200 "EXIF for $testimageid image";
}
CloudFlare + nginx, или экономим при помощи «кофеварки» (upd2: сверкороткий кеш динамики!)