How to use SSL for a backend EC2 instance without a domain

Viewed 2035

I have an AWS EC2 instance set up running my back-end, and it's able to communicate with my front-end (locally), but not with front-end deployed (on Netlify).

Is it necessary to create a domain name for my EC2 instance so I can use SSL? There's no point to have a domain name to my back end since it's just there for the API calls.

How do I use SSL for my backend server without a domain name? Every video and blog I've found requires a domain name. If anyone can point me to the right resource, would appreciate it.

2 Answers

You can enable SSL on an EC2 instance without a domain using a combination of Caddy and nip.io.

nip.io is allows you to map any IP Address to a hostname without the need to edit a hosts file or create rules in DNS management.

Caddy is a powerful open source web server with automatic HTTPS.

  1. Install Caddy on your server

  2. Create a Caddyfile and add your config (this config will forward all requests to port 8000)

    <EC2 Public IP>.nip.io {
        reverse_proxy localhost:8000
    }
    
  3. Start Caddy using the command caddy start

You should now be able to access your server over https://<IP>.nip.io

enter image description here

I wrote an in-depth article on the setup here: Configure HTTPS on AWS EC2 without a Custom Domain

Sadly yes to use SSL-certificates you need to have a valid DNS name so it can process it when you are calling it, anyways if what you want to encrypt is the info you could just use your own encryption method and send the data encrypted to frontend, then use something like crypto.js to use it once decrypted, but the best practice would be giving the backend it's own DNS, that way if at some point the API grows to the point it can be used by others for business you can have them point at something named (and also you don't need to deal with the whole manual encryption/decryption).

Related