Skip to content

Commit

Permalink
add self-signed https between LB + Web servers within the VPC (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
IsmailM authored Oct 14, 2020
1 parent b7b0164 commit 37b9d5e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .ebextensions/https-instance-securitygroup.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Resources:
sslSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
FromPort: 443
CidrIp: 0.0.0.0/0
6 changes: 3 additions & 3 deletions .elasticbeanstalk/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
branch-defaults:
prod-live:
environment: Phenopolis-prod
environment: phenopolis-production-live
dev-live:
environment: Phenopolisapi-dev-env
environment: phenopolis-development-live
environment-defaults:
Phenopolis-prod:
phenopolis-production-live:
branch: null
repository: null
global:
Expand Down
22 changes: 22 additions & 0 deletions .platform/hooks/postdeploy/01_install_ssl_certificates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

if [ -f "/etc/pki/tls/certs/server-key.pem" ]; then
echo '/etc/pki/tls/certs/server-key.pem already exists'
else
openssl req -x509 -sha256 -nodes -newkey rsa:4096 -days 365 \
-keyout /etc/pki/tls/certs/server-key.pem \
-out /etc/pki/tls/certs/server-cert.pem \
-subj "/C=GB/ST=London/L=London/O=Phenopolis/OU=Org/CN=api-live.phenopolis.org"
fi

if [ -f "/etc/nginx/conf.d/webapp-ssl.conf" ]; then
echo '/etc/nginx/conf.d/webapp-ssl.conf already exists'
else
mv /etc/nginx/conf.d/webapp-ssl.pre /etc/nginx/conf.d/webapp-ssl.conf
fi

echo "Restarting nginx"
nginx -t
nginx -s reload
25 changes: 25 additions & 0 deletions .platform/nginx/conf.d/webapp-ssl.pre
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
server {
listen 443 ssl;
server_name _ localhost; # need to listen to localhost for worker tier

ssl_certificate /etc/pki/tls/certs/server-cert.pem;
ssl_certificate_key /etc/pki/tls/certs/server-key.pem;

ssl_session_timeout 5m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;

proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
gzip_static on;
gzip on;
}
}

0 comments on commit 37b9d5e

Please sign in to comment.