gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:57:56 24 4
gpt4 key购买 nike

我将乘客独立用于我的应用程序。目前我的应用程序同时在 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;
}

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

我不知道是弹性负载平衡器的问题还是乘客配置的问题。我想当我停止乘客和用户尝试访问应用程序时。由于创建了新实例而产生的请求超时。我不确定。

提前致谢:)

最佳答案

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

乘客.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 的配置

请引用这个 link

关于ruby-on-rails - 如何使用 aws 弹性负载均衡器将 http 请求强制重定向到旅客独立中的 https?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47221383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com