ruby-on-rails – 使用来自ACM的证书在elasticbeanstalk中强制https
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ruby-on-rails – 使用来自ACM的证书在elasticbeanstalk中强制https,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2214字,纯文字阅读大概需要4分钟。
内容图文
![ruby-on-rails – 使用来自ACM的证书在elasticbeanstalk中强制https](/upload/InfoBanner/zyjiaocheng/825/1cb1b848e3df4856946fd1fb66d7f577.jpg)
我已经配置了可扩展的EB(Elasticbeanstalk)rails(puma)实例.我已通过ACM(亚马逊证书管理器)申请https并将其应用于我的负载均衡器.现在为我的网站启用了HTTPS.但是如何强制重定向到https?我已经尝试了一些在线解决方案,建议通过.ebextensions手动进行nginx配置设置,我不知道从哪里获得ACM的证书?(我假设现在ACM无法做到这一点? ).如何强制HTTPS?
解决方法:
当前的AWS EB Rails和Node.js设置都使用nginx(如果您的Web服务器是apache,请参阅this answer),因此以下内容应该可以使用(改编自this question):
使用以下内容创建文件.ebextensions / 01-force-https.config(.config很重要,而不是.conf).
如果您的环境是单个实例:
files:
"/etc/nginx/conf.d/01-force-https.conf":
owner: root
group: root
mode: "000644"
content: |
server {
listen 8080;
return 301 https://$host$request_uri;
}
如果你的环境是负载平衡的,你遗憾的是不能简单地添加到现有的配置,但需要用sed修改它:
files:
"/tmp/45_nginx_https_rw.sh":
owner: root
group: root
mode: "000644"
content: |
#! /bin/bash
CONFIGURED=`grep -c "return 301 https" /opt/elasticbeanstalk/support/conf/webapp_healthd.conf`
if [ $CONFIGURED = 0 ]
then
sed -i '/listen 80;/a \ if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; }\n' /opt/elasticbeanstalk/support/conf/webapp_healthd.conf
logger -t nginx_rw "https rewrite rules added"
exit 0
else
logger -t nginx_rw "https rewrite rules already set"
exit 0
fi
container_commands:
00_appdeploy_rewrite_hook:
command: cp -v /tmp/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/appdeploy/enact
01_configdeploy_rewrite_hook:
command: cp -v /tmp/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/configdeploy/enact
02_rewrite_hook_perms:
command: chmod 755 /opt/elasticbeanstalk/hooks/appdeploy/enact/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_nginx_https_rw.sh
03_rewrite_hook_ownership:
command: chown root:users /opt/elasticbeanstalk/hooks/appdeploy/enact/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_nginx_https_rw.sh
然后将其添加到您的git repo或app bundle和eb deploy.这将创建/etc/nginx/conf.d/01-force-https.conf,它自动包含在/etc/nginx/nginx.conf中.请注意,如果稍后从.ebextensions中删除相应的文件,eb deploy将不会删除服务器上的文件.另外,我发现以下有助于通过eb ssh进行调试:
sudo service nginx configtest
sudo service nginx restart
内容总结
以上是互联网集市为您收集整理的ruby-on-rails – 使用来自ACM的证书在elasticbeanstalk中强制https全部内容,希望文章能够帮你解决ruby-on-rails – 使用来自ACM的证书在elasticbeanstalk中强制https所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。