in Education by
I've got a Node.js powered site that I'm running on Amazon Elastic Beanstalk. My Node.js app listens on port 8080, and I'm using the nginx elastic load balancer configuration with my EB app, listening on port 80 and 443 for HTTP and HTTPS. However, I only want to accept traffic in my app that has come via HTTPS. I could rig something up in the app to deal with this, but am interested in a way to get the load balancer to redirect all HTTP requests to my site via HTTPS. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Configure your environment so that it can respond to both the ports 80 and 443. Then create .ebextensions folder inside your main node.js application folder. Create a file inside called 00_nginx_https_rw.config, and the content inside looks like: files: "/tmp/45_nginx_https_rw.sh": 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 ] then 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 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 This configuration will create a deployment hook which makes the changes inside /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf by adding rewrite rules. If you want to undo this later, use the below scripts to do so: /opt/elasticbeanstalk/hooks/appdeploy/enact/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_nginx_https_rw.sh

Related questions

0 votes
    From an architecture perspective, I'm trying to get a better understand of how and where files deployed to eb (t2) ... ec2(t2) server? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I want to redirect all the HTTP request to https request on elb. I have 2 ec2 instances. I am using nginx for ... some advice on it. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I just signed up for Amazon's new Elastic Beanstalk offering. What I can't figure out is how to SSH to a ... instance on my behalf. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Can someone differentiate between EC2 and Elastic Beanstalk? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    When you setup an Auto Scaling groups in AWS EC2 Min and Max bounds seem to make sense: The minimum number of ... is larger than Min? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    There are two web-apps: an app for desktop browser; an app for mobile browser; Ahead of them ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    I'm looking for a way to configure Nginx to access hosted services through a subdomain of my server. Those services ... me with this? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    How can I find out the instance id of an ec2 instance from within the ec2 instance? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    I have a use case where I programmatically bring up an EC2 instance, copy and executable file from S3, run it and ... using the CLI ? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I installed Ubuntu 12.04 on my instance and am trying to install packages using apt-get, but I am getting the ... do I fix this? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I have thought a lot recently about the different hosting types that are available out there. We can get ... added probably. Thanks Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Bit confused here, I have an on-demand instance but do I get charged even when I stop the instance? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I know this is not directly a programming question, but people on stackoverflow seems to be able to answer ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I know this is not directly a programming question, but people on stackoverflow seems to be able to answer ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    I've got two different apps that I am hosting (well the second one is about to go up) on Amazon EC2. ... path ; ec2-describe-instances Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
...