Redirect http to https google cloud load balance

☆樱花仙子☆ 提交于 2019-12-13 20:50:19

问题


I have created https load balance and added ssl certificate. site working with https:// but its not working http:// and getting 404 error

Added Headername as X-Forwarded-Proto and avlue as https in load balace header request

Added in .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

is there any to redirect http to https to avoid 404 error?


回答1:


At this time, there is no way to directly configure the GCP Load Balancer to redirect traffic from HTTP to HTTPS; however, there is a workaround to do this. Using Nginx, you can add the following string within the nginx configuration file:

if ($http_x_forwarded_proto = "http") { 
      return 301 https://$host$request_uri; 
    }

If you are using Apache, then you will have to do the following if you want to redirect the traffic using the .htaccess file:

  1. Run either "sudo a2enmod rewrite" or "LoadModule rewrite_module modules/mod_rewrite.so" depending on the Linux OS you are running. This will enable
  2. Edit or create the .htaccess file in the domain root directory with the following:

    RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

You can find more details on the following link here.

There is also an internal request to have this feature added within GCP HTTP/HTTPS Load Balancers. I cannot provide an ETA on if/when it will be applied; however, you can follow the Public Issue Tracker (PIT) on the progress of the request.



来源:https://stackoverflow.com/questions/58246708/redirect-http-to-https-google-cloud-load-balance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!