/ mozey.co / blog

ec2 multiple ssl virtualhosts

July 1, 2015

EC2 allow you to setup Multiple Private IP Addresses

🔗 Each virtual HTTPS virtual host must listen on its own private IP address

<VirtualHost 172.30.2.135:443>

<VirtualHost 172.30.2.159:443>

🔗 Associate a public Elastic IPs with each private IP used by the instance

🔗 Setup networking on the instance to recognize all required interfaces

For Ubuntu 14.04

ifconfig -a

cd /etc/network/interfaces.d

sudo cp eth0.cfg eth1.cfg

sudo vi eth1.cfg

sudo ifup eth1

ifconfig -a

🔗 Setup routing for the second interface

Multiple IP addresses on Amazon EC2

provide a different route for the second ip

Print routing table

route

This returns the instance public IP

curl --interface 172.30.2.135 ifconfig.me

This does not return anything and should timeout

curl --interface 172.30.2.159 ifconfig.me

Apache virtual hosts seems to be up and running correctly:

wget https://172.30.2.135

wget https://172.30.2.159

Add the route

sudo ip rule add from 172.30.2.159 table default

sudo ip route add default via 172.30.2.1 dev eth1 table default

sudo ip route flush cache