我配置了一个可伸缩的EB(Elasticbeanstalk)rails(puma)实例。我已通过ACM(亚马逊证书管理器)申请https并将其应用到我的负载均衡器。现在我的网站已启用HTTPS。但我如何强制重定向到https?我在网上尝试了一些解决方案,建议通过.ebextensions手动创建一个nginx配置设置,我不知道从哪里获得ACM的证书?(我认为现在对于ACM是不可能的? )。我如何强制使用HTTPS?使用来自ACM的证书强制使用elasticbeanstalk中的https
5
A
回答
4
目前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回购或应用程序包和eb deploy
。这会创建自动从/etc/nginx/nginx.conf
包含/etc/nginx/conf.d/01-force-https.conf
。请注意,如果稍后从.ebextensions
删除相应的文件,eb deploy
将不会删除服务器上的文件。另外,我发现在调试以下有用通过eb ssh
:
sudo service nginx configtest
sudo service nginx restart
+0
谢谢!很好的答案 – thomasstephn
相关问题
- 1. 使用https中的证书
- 2. 如何配置弹性beanstalk以使用https与ACM证书?
- 3. 使用自签名证书的HTTPS!
- 4. 在Elastic Beanstalk中使用AWS证书管理器(ACM证书)
- 5. egit使用自签名证书,https
- 6. 如何通过自动证书管理强制HTTPS嵌入在Heroku上使用自动证书管理
- 7. 通过https使用Java使用证书来使用RESTful服务
- 8. 使用Flask的before_request强制使用HTTPS()
- 9. kSecTrustResultRecoverableTrustFailure使用NSURLConnection连接到使用自签名证书的https
- 10. PowerShell HTTPS GET使用证书库中的客户端证书
- 11. 使用证书认证来调用HTTPS WCF服务
- 12. 如何使用证书身份验证来调用HTTPS URL
- 13. GoDaddy和ElasticBeanStalk的SSL证书
- 14. 使用具有HTTPS证书的System.Net.WebClient
- 15. 使用WildCard SSL证书的HTTPS WCF
- 16. 强制WCF使用HTTPS
- 17. 使用.htaccess强制HTTPS
- 18. 强制mod_speling使用https
- 19. 强制WWW使用HTTPS
- 20. 如何使用JSoup轻松使用HTTPS(自签名证书)?
- 21. 如何在grails中使用* .p12证书来建立https连接?
- 22. 使用的.htaccess强制HTTP或HTTPS
- 23. 使用自签名证书的Java ssl/https客户端
- 24. 使用自定义证书的Android https连接
- 25. 在WebFlow中强制使用https
- 26. 在SYMFONY中强制HTTPS仅使用HTACCESS
- 27. 在Mac应用程序中使用来自Keychain的证书
- 28. 使用自签名证书在iOS 9中进行HTTPS请求
- 29. HTTPS不能在tomcat中使用自签名证书
- 30. 如何使用android aws sdk从ACM获取SSL证书?
我跟着这个http://msnider.github.io/blog/2013/12/06/force-https-slash-ssl-on-amazon - 弹性beanstalk /和它的工作。您可能必须手动重新启动服务器才能正常工作?或者只是上传和部署。我还隐约记得必须将我的负载均衡器别名到我的域以获得我的证书才能工作,但这可能是因为我购买了扩展验证证书。 – vath
似乎互联网无法就这个问题达成一个单一的,完整的和有效的解决方案。希望你能得到一些帮助[在我的帖子中](http://thehunk.blogspot.in/2017/11/how-to-force-redirect-http-to-https-in.html)。最后,我不得不跳过这个谜团。 – ADTC