recently i needed to setup a secure domain on an EC2 instance (need to use the Google Maps Javascript API and it requires HTTPS domains). the application architecture was;
- angularjs (front-end)
- NodeJS (front-end server) http://:3000
- spring-boot (data server) http://:8080
to get this working on EC2, nginx was added to help act as a HTTPS terminator and router for the NodeJS instance.
domain routing --> name.com
this is not a permanent solution, just a demo, so I used and A record at name.com to point to my Elastic IP address. the trick here is to add 2 A records; [blank].example.com --> [elastic IP] and *.example.com --> [elastic IP]. this needs to be done to support https://letsencrypt.org
letsencrypt.org
the steps to follow (on ubuntu) are
- sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
- sudo apt-get install nginx
- sudo vi /etc/nginx/sites-available/default
- add location ~/.well-known { allow all; }
- sudo ./letsencrypt-auto certonly -a webroot --webroot-path=/usr/share/nginx/html -d example.com -d www.example.com
- (go through the on screen prompts)
- sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
- add ssl to the nginx default
- add redirect on port 80 to 443 (HTTP 301)
below is an example of the nginx default file
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name sexample.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
location ~ /.well-known {
allow all;
}
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
No comments:
Post a Comment