Tuesday, August 23, 2016

nginx ubuntu and and

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

this is not a permanent solution, just a demo, so I used and A record at to point to my Elastic IP address.  the trick here is to add 2 A records; [blank] --> [elastic IP] and * --> [elastic IP].  this needs to be done to support

the steps to follow (on ubuntu) are
  1. sudo git clone /opt/letsencrypt
  2. sudo apt-get install nginx
  3. sudo vi /etc/nginx/sites-available/default
  4. add     location ~/.well-known { allow all; }
  5. sudo ./letsencrypt-auto certonly -a webroot --webroot-path=/usr/share/nginx/html -d -d
  6. (go through the on screen prompts)
  7. sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
  8. add ssl to the nginx default
  9. add redirect on port 80 to 443 (HTTP 301)
below is an example of the nginx default file

server {
    listen 80;
    return 301 https://$host$request_uri;

server {
    listen 443 ssl;


    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    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