使用Nginx在重写时设置标头

时间:2020-06-05 11:19:54

标签: wordpress nginx nginx-config

我已经为WordPress编写了一个Nginx配置,它将在缓存的文件夹中提供文件。

当文件通过缓存提供服务时,我想添加响应标头x-flying-press-cache: HIT。即使我添加了add_header,它似乎也无法进行重写。

set $flying_press_cache 1;
set $flying_press_url "/wp-content/cache/flying-press/$request_uri/index.html";
set $flying_press_file "$document_root/wp-content/cache/flying-press/$request_uri/index.html";

if ($request_method = POST) {
  set $flying_press_cache 0;
}

if ($is_args) {
  set $flying_press_cache 0;
}

if ($http_cookie ~* "(wp\-postpass|wordpress_logged_in|comment_author|woocommerce_cart_hash)") {
  set $flying_press_cache 0;
}

if (!-f "$flying_press_file") {
  set $flying_press_cache 0;
}

if ($flying_press_cache = 1) {
  add_header x-flying-press-cache HIT;       -> Not working
  rewrite .* "$flying_press_url" last;
}

0 个答案:

没有答案