繁体   English   中英

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

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

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

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

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/

我尝试了这两种方法

1)

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

2)

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

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

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

提前致谢 :)

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

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

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

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"
}

您需要使用与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;
     }

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

请参阅此链接

暂无
暂无

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

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