ruby on rails - Forcing https in elasticbeanstalk with certificate from ACM -


i have provisioned scalable eb(elasticbeanstalk) rails(puma) instance. have applied https through acm(amazon certificate manager) , applied load balancer. https enabled website now. how force redirect https? have tried number of solutions online suggested make nginx configuration setting manually through .ebextensions , not sure certificate acm this?(i assuming not possible acm right now?). how force https?

the current aws eb rails , node.js setups both use nginx (if web server apache see this answer), following should work (adapted this question):

create file .ebextensions/01-force-https.config (the .config important, not .conf) following content.

if environment single instance:

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;       } 

if environment load balanced, unfortunately cannot add existing config need modify 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 ]                   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 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 

then add git repo or app bundle , eb deploy. creates /etc/nginx/conf.d/01-force-https.conf automatically included /etc/nginx/nginx.conf. note eb deploy won't delete file on server if later remove corresponding file .ebextensions. also, found following helpful in debugging through eb ssh:

sudo service nginx configtest sudo service nginx restart 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -