如何使用aws弹性负载均衡器强制将http请求重定向到独立乘客的https?

[英]How can i forcefully redirect http request to https in passenger standalone with aws elastic load balancer?


I used passenger standalone for my app. currently my app is running on both http and https . i want to redirect all http request to https. I used load balancer in my application. I read this articles

我在我的应用程序中使用了独立乘客。目前我的应用程序在http和https上运行。我想将所有http请求重定向到https。我在我的应用程序中使用了负载均衡器。我读过这篇文章

https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template

https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template

http://code.eklund.io/blog/2015/03/17/managing-rewrites-for-a-rails-app-on-heroku-with-nginx-plus-phusion-passenger/

http://code.eklund.io/blog/2015/03/17/managing-rewrites-for-a-rails-app-on-heroku-with-nginx-plus-phusion-passenger/

i tried this 2 methods

我尝试了这两种方法

1)

1)

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

2)

2)

if ($http_x_forwarded_proto != "https") {
      rewrite ^(.*)$ https://$server_name$REQUEST_URI permanent;
  }

i tried all process in same way. but every time it goes in to infinite loop and before i start passenger the instance terminate itself and create new instance because of too many request timeout.

我以同样的方式尝试了所有过程。但每次进入无限循环时,在我开始乘客之前,实例会因为请求超时太多而终止自身并创建新实例。

I can't figure out, whether it is issue of elastic load balancer or passenger config. I think when i stop passenger and user try to access app. the request time out generated and due to that new instance created. i am not sure.

我无法弄清楚,无论是弹性负载平衡器还是乘客配置问题。我想当我停止乘客和用户尝试访问应用程序。生成请求超时以及由于创建了新实例。我不确定。

Thanks in advance :)

提前致谢 :)

2 个解决方案

#1


1  

You can do this at the proxy level, or at the app level. To do it at the app level:

您可以在代理级别或应用级别执行此操作。要在应用级别执行此操作:

# config/environments/production.rb
...
config.force_ssl = true
...

#2


1  

I hope your all certificates are installed correctly and pointing to the right path. If not check the below configuration

我希望您的所有证书都正确安装并指向正确的路径。如果没有,请检查以下配置

Passenger.json

Passenger.json

{
  "environment": "production",
  "instance_registry_dir": "/var/run/passenger-instreg",
  "daemonize": true,
  "user": "myappuser",
  "port": 443,
  "ssl": true,
  "ssl_certificate": "/path/to/ssl_cert.pem",
  "ssl_certificate_key": "/path/to/ssl_key.pem",
  "nginx_config_template": "/path/to/nginx.conf.erb"
}

You need to use the same configuration which you use for nginx for redirecting from http to https

您需要使用与nginx相同的配置来从http重定向到https

http {
     server_tokens off;
        server {
            listen 80 default_server;
            listen [::]:80 default_server;

            # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
             return 301 https://$host$request_uri;
     }

Latest Link
Here is the configuration of standalone passenger to redirect from http to https latest_link

最新链接以下是从http重定向到https latest_link的独立乘客的配置

Please refer this link

请参阅此链接


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2017/11/10/87b26218048edc68237989af6ca6309b.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号