我正在尝试为 nginx (0.7.67) 上的静态文件配置 Expires 标头。静态文件由 Golang 反向代理提供:
location /rev/ {
proxy_pass http://localhost:8910/;
proxy_redirect off;
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 https;
# I am putting this here, because nginx only uses one location. Is this OK?
location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
expires 30d;
}
}
当我这样做时,重新启动 nginx 没有错误,但不再提供静态文件。
我已经尝试过以下星座,但它不起作用:
server {
...
location /rev/ {
proxy_pass http://localhost:8910/;
proxy_redirect off;
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 https;
}
location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
expires 30d;
}
}
问题:如何为位于反向代理后面的应用程序上的静态文件应用过期标头?