Skip to content

Instantly share code, notes, and snippets.

@sanjarcode
Last active April 16, 2022 08:08
Show Gist options
  • Save sanjarcode/52e2d0b5286ffa9982eb8baef0e4772f to your computer and use it in GitHub Desktop.
Save sanjarcode/52e2d0b5286ffa9982eb8baef0e4772f to your computer and use it in GitHub Desktop.
Setup domain and hosting on server
### EC2 restart
If your server is restarted, its public IPv4 address may change, in that case,
just update the `Route 53` type A record with the new address.

Procedure source: https://youtu.be/qor31Egu0Rg (applicable till 4:40 for Express.js)

Setup EC2

  1. Spin up an EC2 instance on AWS
  2. Go to EC2 Dashboard and right click on your instance
  3. Select 'Security' -> 'Change Security Groups'
  4. See the 'Associated Security Group' entry, remember it.
  5. On the left app bar, select 'Network and Security' -> 'Security Groups'
  6. Right click on the remembered(step 4) group.
  7. Select 'Edit Inbound Rules'.
  8. Add two rules: HTTP and HTTPS, set source for both to be 'IPv4 Anywhere'. Done.

Setup Route 53

  1. Choose Route 53 from list of AWS services.
  2. Go to 'DNS Management' -> click 'Create Hosted Zone'
  3. Enter your domain and select 'Public Hosted Zone', enter 'OK'*.
  4. 2 Records are created. Create new 'Record', of type 'A IPv4', and add the EC2 instance's Public IPv4 as value. Click 'ok'.
  5. Create another record of type 'CNAME', add 'www' in prepend box and 'safaq.me' as 'value'. Done.

Setup DNS Nameserver

  1. Go to your domain registrar.
  2. Go to DNS edit options.
  3. Add 4 domain like strings from step 4's Record (type: NA) (created automatically), without the ending period as the 4 name servers. Done.

Start the server

  1. 'Connect' to your EC2 instance.
  2. Run the command screen, reason.
  3. Start the server on PORT 80. e.g. I was using Express.js, this needs root priveleges for PORT 80. Go root by running sudo su, then PORT=80 node path_to_server/server.js.

You're live 🚀!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment