我配置了一個可伸縮的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