I'm writing a reverse proxy for a site.
It work's fine but i'd like to add/modify headers for assets.
If i remove the proxy pass from each location block it stops proxying for the asset blocks, i foolishly assumed that the /
root location block would take precedence and apply further down.
I've used try_files $uri @proxy
and created a location @proxy
block, but it feels ugly with NGINX looking for the files that will never be locally.
I'm asking how i can avoid duplication like this:
location / {
proxy_pass https://web1.local;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ~* .(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|ttf|otf|woff|woff2|eot)$ {
proxy_pass https://web1.local;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
expires max;
access_log off;
add_header Cache-Control "public";
add_header X-Asset "Yes";
}
location ~* .(?:css|js)$ {
proxy_pass https://web1.local;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
expires 1M;
access_log off;
add_header Cache-Control "public";
add_header X-Asset "Yes";
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…