I am attempting to redirect all non-www requests to www with my nginx server, but despite successfully redirecting the http request (http://example.com to https://www.example.com), the https request gets hung up. I have read where the browser tries to read the ssl certificate before the redirect and due to this, the hang up can occur, but I recently created a new ssl certificate to include example.com, so I don't believe that should be an issue. Here are the details of my setup:

Route53, Elastic Beanstalk, Load Balancer, S3

  • My Elastic Beanstalk instance is using a Classic Load Balancer with the SSL certificate attached.


  • SSL Certificate for www.example.com (primary), example.com, .example.com


  • S3 set to redirect non-www requests to www


  • DNS configured for example.com to point to the s3-bucket redirect


  • Nginx config to force https
owner: root
group: root
mode: "000644"
content: |
#! /bin/bash

CONFIGURED=`grep -c "return 301 https" /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf`

if [ $CONFIGURED = 0 ]
sed -i '/listen 8080;/a \ if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; }\n'

/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf logger -t nginx_rw "https rewrite rules added" exit 0 else logger -t nginx_rw "https rewrite rules already set" exit 0 fi

command: cp -v /tmp/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/appdeploy/enact
command: cp -v /tmp/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/configdeploy/enact
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

  • What does "gets hung up" mean? This isn't really a sensible description of a problem or error. Exactly what is happening? What is your domain name? – Michael Hampton Aug 12 '18 at 21:15
  • Hung up as in the server took too long to respond and times out after a long request. Is there additional information that would be helpful in providing support? – cphill Aug 13 '18 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.