I recently needed to set up HTTPS for my side project, better404.com. Amazon makes it easy to set up by uploading it directly to an ELB but in my case it’s hosted on a single AWS instance so I didn’t want to pay for an ELB that would be more expensive than my one instance. I’ve heard horror stories and expected the worst but it turned out surprisingly easy. Hopefully these steps can help someone else out.
- Get an HTTPS certificate. I bought three certificates from Namecheap a couple of months ago when they were running a promotion.
- Go through the certificate generation process. I found this guide that explains how to do it detail and worked well for me. The only things I had to change where the Nginx certificate configuration folder path (/opt/local/nginx/conf/certs => /etc/nginx/certs/) and replacing the filenames to be more specific (domain.* to better404.*). Note that this process is not immediate and you will need to send the contents of your CSR file to the SSL provider and they will respond back with the SSL certificate to use.
- Enable SSL in Nginx. The previous guide provides some information here and I’m including the relevant parts from my configuration. I chose to redirect all traffic to HTTPS rather than supporting both simultaneously.
- Allow Nginx to bind to the IP address. One thing that’s not mentioned in the guide and required a bit of digging around is that you need to allow Nginx to bind to the non local IP address - otherwise it can only access the private IP address set by AWS. There’s a quick guide on how to do this I found on StackOverflow.
If you have any questions feel free to leave a comment and I’ll try to help out.