覆盖响应位置标头[nginx]

时间:2018-01-24 20:24:53

标签: nginx

我已经进行了以下设置(仅显示相关指令):

# /etc/nginx/nginx.conf
http {
  map $sent_http_content_type $my_content_type {
    default $sent_http_content_type;
  }

  map $sent_http_location $original_redirect {
    default $sent_http_location;
  }

  map $sent_http_location $my_redirect {
    default $sent_http_location;
    http://localhost/redirect http://my.testing.test/redirect
  }

  include /etc/nginx/sites-available/*.conf;
}

# /etc/nginx/sites-available/mysite.conf;
server {
  listen 80;
  server_name localhost *.testing.test;

  location ~ \.php$ {
    root /var/www/html;

    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTP_PROXY "";
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    # fpm is our fpm service's DNS name
    fastcgi_pass fpm:9000;
    fastcgi_index index.php;

    add_header Location $my_redirect;
    add_header ORIGINAL-LOCATION $original_redirect;
    add_header MY-CONTENT-TYPE $my_content_type;
  }
}

我尝试做的是覆盖响应中的Location标头,因为我们的应用程序有很多遗留代码真的想要将自己视为居住在http://localhost。因此,如果回复中包含Location: http://localhost/redirect标题,我想将其替换为Location: http://my.testsite.test的新标题。

不幸的是,无论我做什么,nginx似乎都没有$ sent_http_location中的任何内容。即使我把它放在自定义标题中,也没有任何东西(所以标题没有设置)。还有其他标题设置,我可以在nginx中读取它们。例如,在上面的配置中,正在读取Content-Type标头,并且它正在新的自定义标头中重置。

我在这里做错了尝试阅读Location标题吗?还是有另一种方式来做我想要实现的目标?如果可能的话,我想避免使用反向代理。

0 个答案:

没有答案
相关问题