简体   繁体   English

天青网关https后端池和htaccess重定向循环

[英]azure gateway https backend pool and htaccess redirect loop

I have the htaccess rewrite rule: 我有htaccess重写规则:

RewriteCond %{HTTP_HOST}: ^(?:www\.)?samplesite\.net
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

on two azure vm running IIS. 在运行IIS的两个Azure虚拟机上。 I have an application gateway sitting in front that has a backend Https pool with the server certs of the two azure vms. 我有一个位于前面的应用程序网关,该网关具有一个后端Https池,其中包含两个天蓝色的vms的服务器证书。

I have a multi-site https listener on the gateway listening for https traffic to the gateway with the specific URI www.samplesite.net. 我在网关上有一个多站点https侦听器,用于侦听具有特定URI www.samplesite.net的https到网关的流量。 There is an attached rule that uses the backendHttps pool. 有一个附加规则使用backendHttps池。

The VMs host multiple sites and I only want to redirect HTTP to HTTPS for this one site. VM托管多个站点,而我只想将此站点的HTTP重定向到HTTPS。 I have the private key for www.samplesite.net on Azure gateway for the listener. 我在侦听器的Azure网关上具有www.samplesite.net的私钥。

If I point directly at any VM I am successfully redirected to HTTPS. 如果我直接指向任何VM,则可以成功重定向到HTTPS。 If I point at the gateway I receive a too many redirect error. 如果我指向网关,则会收到太多重定向错误。

If I do not rewrite on the server I can go directly to HTTPS or HTTP with no issue via the gateway. 如果不在服务器上重写,则可以直接通过网关直接转到HTTPS或HTTP。

Why am I getting this redirect if I have end to end encryption? 如果我具有端到端加密,为什么要获得此重定向?

Edit: In relation to using gateway rules to redirect traffic: 编辑:关于使用网关规则重定向流量:

Rules are processed in the order they are listed, and traffic is directed using the first rule that matches regardless of specificity. 规则按照列出的顺序进行处理,并且使用匹配的第一个规则(不管具体如何)对流量进行定向。 For example, if you have a rule using a basic listener and a rule using a multi-site listener both on the same port, the rule with the multi-site listener must be listed before the rule with the basic listener in order for the multi-site rule to function as expected. 例如,如果您在同一端口上同时具有使用基本侦听器的规则和使用多站点侦听器的规则,则在使用基本侦听器的规则之前,必须在使用基本侦听器的规则之前列出具有多站点侦听器的规则-site规则可以正常运行。

Edit2: If anyone is interested I had to do this: Edit2:如果有人感兴趣,我必须这样做:

RewriteCond %{HTTP_HOST}: ^(?:www\.)?samplesite\.net
RewriteCond %{HTTP_X_FORWARDED_PROTO} ^http$
RewriteRule ^(.*)$ https://www.samplesite.net%{REQUEST_URI} [L,R=302]

I had to check the header forwarded from the gateway 我必须检查从网关转发的标头

> RewriteCond %{HTTP_HOST}: ^(?:www\.)?samplesite\.net 
> RewriteCond %{HTTP_X_FORWARDED_PROTO} ^http$ 
> RewriteRule ^(.*)$ https://www.samplesite.net%{REQUEST_URI} [L,R=302]

https://www.helicontech.com/isapi_rewrite/doc/examples.htm https://stackoverflow.com/a/41512717/7889282 https://www.helicontech.com/isapi_rewrite/doc/examples.htm https://stackoverflow.com/a/41512717/7889282

https://sitecoreblog.marklowe.ch/2017/01/using-ip-geolocation-and-ssl-on-azure/ https://sitecoreblog.marklowe.ch/2017/01/using-ip-geolocation-and-ssl-on-azure/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM