Skip to content

Instantly share code, notes, and snippets.

@albert-yu
Last active March 19, 2021 19:05
Show Gist options
  • Save albert-yu/b605be23ac5f494b0c1aab5fff92f52f to your computer and use it in GitHub Desktop.
Save albert-yu/b605be23ac5f494b0c1aab5fff92f52f to your computer and use it in GitHub Desktop.
Notes and instructions for deploying React app with nginx and Certbot to EC2 instance

Getting certs for HTTPS

  1. Run yarn build or npm run build on your local machine. scp it over to the EC2 box (you can compress it into a build.zip file and then unzip once it's copied).
  2. Install docker and docker-compose on the EC2 box following these instructions.
  3. Create sym link for docker-compose: sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  4. Install git on the EC2 if you haven't already. Then clone this repo onto the box. cd into the repo.
  5. Following the README from the above repo, update all necessary configurations (email address, server names).
  6. Run sudo "PATH=$PATH" sh init-letsencrypt.sh.
  7. The generated certs should be at ./data/certbox/live/sub.mysite.com/fullchain.pem and ./data/certbox/live/sub.mysite.com/privkey.pem. Look at the volumes section in the docker-compose.yml in case the configuration is different.
  8. Now, you can serve your React app with nginx, or use a simple Go server to do it.

NOTE: The docker container contains a cron job (I think) that renews the certificates from time to time. I would probably run this separately, outside the container.

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