Nginx配置A域名请求B域名

1.重定向(请求由A域名变为B域名)

location /test {
  return 307 $scheme://test.B.com$request_uri;
}

307:解决了POST请求经过Nginx到服务变为GET请求

或者(去掉location)

location /test {
  rewrite ^/test/(.*)$ $scheme://test.B.com/$1 break;
}

2.代理(请求看到域名不变,还是A域名)

location /test/ {
	client_max_body_size  1024m;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "Upgrade";
	proxy_set_header Host "test.B.com";
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-From-IP $remote_addr;
	proxy_set_header X-Forwarded-Proto $scheme;
	proxy_set_header X-Remote-Port $remote_port;
	proxy_pass http://test.B.com/;
}

主要是:proxy_set_header Host "test.B.com";

你可能感兴趣的:(计算机网络,javaweb,分布式相关,nginx)