Nginx reverse proxied Ubuntu instance, provisioned by these deployment scripts

Last updated: 2024-08-28 20:39:04

This repo contains scripts for auto set up of and deployment to a Linux Debian Ubuntu distribution, to carry out the following:


Variable configuration:

The below sensitive variables must be defined for these scripts to operate. Create a /.env file with the correct values for the following variables:

In /.env:

Variable Description
SERVER Virtual machine public IP
SERVER_NAME Domain name (set with correct DNS settings defined)
USER Name for the user that will replace ubuntu for administration
SSH_KEY Path to the private SSH key
CF_API_TOKEN CloudFlare API token with the assigned domain's DNS editing permissions
ZONE_ID The zone id of the assigned domain name
RECORD_ID The DNS record ID number that needs updating on restart
RECORD_NAME The DNS record name number that needs updating on restart

/settings.sh will then source your /.env file and export it's variable values to it's runtime environment for the scripts to use. /settings.sh also defines some non-sensitive variables vales that the scripts may use.


To run the scripts:

  1. Clone this repository.
  2. CD into the repository.
  3. Create a local /.env and populate with correct values for variables listed in the configuration table above.
  4. Setup:

  5. run   ./setup.sh -h` in terminal and read ./setup.sh's help options.
  6. run USER=deploy ./setup.sh in terminal (without arguments runs all units & steps). you must define USER variable in terminal commands with the username that you wish to create on the server and run deployment from, otherwise USER will be set to your local machine's user name!.
  7. Deploy index.html;

  8. run USER=deploy ./deploy.sh in terminal to execute the deploy script. again, you must define USER in the terminal execute command (set as the same user that you setup in setup.sh). You must have an index.html file in the same directory as the deploy.sh script file - this is the HTML file that you are deploying to the server.

Manual configuration required:

HTTPS

To serve via HTTPS, you must manually configure the server to do so, by doing the following:

  1. Get SSL cert & key from provider.
  2. Create an /etc/nginx/ssl directory.
  3. SCP cert & key into server:

      Cert; scp -i ~/path/to/your/ssh-keypair.pem ~/path/to/your/ssl_certificate.crt [email protected]:/home/ubuntu

      Key; scp -i ~/path/to/your/ssh-keypair.pem ~/path/to/your/ssl_certificate_key.key [email protected]:/home/ubuntu

  4. Sudo move the cert & key into /etc/nginx/ssl directory:

      i.e., sudo mv ~/ssl_certificate.crt /etc/nginx/ssl/ssl_certificate.crt

      i.e., sudo mv ~/ssl_certificate_key.key /etc/nginx/ssl/ssl_certificate_key.key

  5. Chmod & chown to nginx user, default user set in /etc/nginx/nginx.conf, usually 'www-data':

      sudo chmod 600 /etc/nginx/ssl/ssl_certificate_key.key

      sudo chown www-data:www-data /etc/nginx/ssl/ssl_certificate_key.key

  6. Update server context in /etc/nginx/sites-available/... with:
  7. ssl_certificate /path/to/cert
  8. ssl_certificate_key /path/to/cert_key
  9. root /path/to/your/html
  10. Define your location route contexts
  11. See example of a server context setup for SSL in this repo; 'nginx/sites-available/default'

DNS (via Cloudflare)

On instance documentation