繁体   English   中英

Rails5.0应用程序默认为HTTPS

[英]Default to HTTPS for Rails5.0 App

我有一个在AWS EB中运行的基本Rails应用程序,并已使用Amazon Certificate Manager启用了SSL层。 如何将“ example.com”自动重新路由到“ https://www.example.com ”? 这样,应用程序就可以为访问的应用程序运行SSL证书。 提前致谢

您将需要将HTTPS重定向配置添加到Rails应用程序的源代码中。 有一种方法可以使用名为.ebextensions的文件夹中的conf文件在Elastic beantalk中进行高级设置。

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html

具体来说,您需要创建一个具有以下内容的conf文件,并将其添加到您的.ebextensions文件夹中。

Files:
"/etc/httpd/conf.d/ssl_rewrite.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
        RewriteEngine On
        <If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
        </If>

请参阅此AWS论坛链接以了解更多详细信息。 https://forums.aws.amazon.com/message.jspa?messageID=739990

将以下行添加到config/environments/production.rb文件:

config.force_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.

暂无
暂无

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

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