{"id":3587,"date":"2021-03-04T07:35:04","date_gmt":"2021-03-04T07:35:04","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=3587"},"modified":"2021-03-04T07:35:07","modified_gmt":"2021-03-04T07:35:07","slug":"redirect-http-to-https-in-tomcat-under-elastic-beanstalk","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2021\/03\/04\/redirect-http-to-https-in-tomcat-under-elastic-beanstalk\/","title":{"rendered":"Redirect http to https in Tomcat under Elastic BeanStalk"},"content":{"rendered":"\n<p>If you want to redirect all HTTP requests to HTTPS , then this is something that is done at the server level; in this case it will be handled by Apache Tomcat. It is assumed that a valid https domain is already configured and the web app is running on it.<\/p>\n\n\n\n<p>We need to create an <em>.ebextensions<\/em> folder under which there will be a custom server.xml which will do the redirection. Within <em>.ebextensions <\/em>there has to be a fixed folder structure as shown below:<\/p>\n\n\n\n<p><em>.ebextensions\/httpd\/conf.d\/<\/em><\/p>\n\n\n\n<p>Under this path we create a file called <em>elasticbeanstalk.conf<\/em>  with the following contents:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;VirtualHost *:80&gt;\n   LoadModule rewrite_module modules\/mod_rewrite.so\n \n   RewriteEngine On\n   RewriteCond %{HTTP:X-Forwarded-Proto} !https\n   RewriteCond %{HTTP_USER_AGENT} !ELB-HealthChecker\n   RewriteRule (.*) https:\/\/%{HTTP_HOST}%{REQUEST_URI}\n \n   &lt;Proxy *&gt;\n     Require all granted\n   &lt;\/Proxy&gt;\n \n   ProxyPass \/ http:\/\/localhost:8080\/ retry=0\n   ProxyPassReverse \/ http:\/\/localhost:8080\/\n   ProxyPreserveHost on\n \n   ErrorLog \/var\/log\/httpd\/elasticbeanstalk-error_log\n \n&lt;\/VirtualHost&gt;\n\n\n<\/pre><\/div>\n\n\n<p>As of March 2021, Beanstalk expects the <em>.ebextensions<\/em> folder to be either under <em>webapp<\/em> or under <em>webapp\/WEB-INF<\/em> . When you create a WAR file open it once to confirm that the <em>.ebextensions<\/em> folder exists in the root. Once you deploy it on AWS, then all http requests to the domain will get redirected to https.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>If you want to redirect all HTTP requests to HTTPS , then this is something that is done at the server level; in this case <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/03\/04\/redirect-http-to-https-in-tomcat-under-elastic-beanstalk\/\" title=\"Redirect http to https in Tomcat under Elastic BeanStalk\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3265,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320,319],"tags":[],"class_list":["post-3587","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","category-java"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=3587"}],"version-history":[{"count":4,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3587\/revisions"}],"predecessor-version":[{"id":3591,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3587\/revisions\/3591"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3265"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=3587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=3587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=3587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}