添加了参数

时间:2015-07-01 19:21:56

标签: nginx configuration dns server devops

我现在一直在nginx上遇到一个奇怪的问题。我有两个nginx服务器,一个托管内容,我想转发到另一台服务器。正在进行转发的那个网站已启用配置:

server {
  listen 80;
  server_name pastdomain.com;
  return 301 https://domain.com$request_uri?from_past_domain=true;
}

server {
  listen 443;
  server_name pastdomain.com;
  return 301 https://domain.com$request_uri?from_past_domain=true;

 # bunch of ssl config here
}

基本上我想将所有流量发送到新服务器,在那里可以使用新的get变量from_past_domain解释它,我可以根据需要在新服务器上解释。

即。 pastdomain.com/thing/thing1/1 /

会转换为

domain.com/thing/thing1/1?from_past_domain=true

现在它似乎正在工作,除非我只是访问pastdomain.com

我改为获得domain.com //?from_past_domain = true

这是不正确的。此外,它不会正确添加新的get参数。

即。如果我有pastdomain.com?test=1&test2=2它转发到domain.com/?test=1&test2=2?from_past_domain=true

如何正确转发?

1 个答案:

答案 0 :(得分:0)

如果要更改URI,则应使用rewrite。在这种情况下,nginx将处理正确的请求参数。

此外,您可以use one server block获取HTTP和HTTPS。

server {
  listen 80;
  listen 443 ssl;
  server_name pastdomain.com;

  rewrite ^(.*)$ https://domain.com$1?from_past_domain=true permanent;

  # bunch of ssl config here
  # DO NOT use `ssl on;`
}
相关问题