Skip to content

Create Nginx Site Configuration

Deploying a new static site on Nginx

This script creates a static site in Nginx with the specified parameters. To use it:

Make the script executable: chmod +x create-staticsite-nginx.sh Run it with sudo, providing the required parameters: The script will:

  1. Create the necessary directory structure
  2. Copy your static files to the web server directory
  3. Create and enable the Nginx configuration
  4. Set appropriate permissions
  5. Restart Nginx to apply the changes

Example usage:

bash
chmod +x create-static-site-nginx.sh

sudo ./create-static-site-nginx.sh -n mysite -p 8080 -d /path/to/dist

sudo ./create-static-site-nginx.sh -n hemap -p 5678 -d /home/kelly/ws/k6/nasu/src/hemap/dist

sudo ./cr-ss.sh -n hemap -d ./dist

curl -Is http://hemap.hanapko.com | head -n 1

Parameters:

  1. The domain name (e.g., example.com)
  2. The path to the directory containing the static files (e.g., /path/to/dist/files)
  3. The port number (optional, default is 80)

Deploying a new site configuration

This script creates a new Nginx site configuration file for a given domain and port. It also creates a symbolic link to the configuration file in the sites-enabled directory and reloads Nginx to apply the changes.

The script takes three arguments:

  1. The domain name (e.g., example.com)
  2. The path to the directory containing the static files (e.g., /path/to/dist/files)
  3. The port number (optional, default is 80)

Make it executable:

bash
chmod +x create-nginx-site.sh

Run it with sudo:

bash
sudo ./create-nginx-site.sh example.com /path/to/dist/files 8080

For subdomains, the port is optional:

bash
sudo ./create-nginx-site.sh app.example.com /path/to/dist/files

sudo ./cr-ss.sh hemap.hanapko.com

# check if the site is up
curl -Is https://hemap.hanapko.com | head -n 1

# enable SSL for the site
sudo certbot --nginx -d hemap.hanapko.com

Deploying a new Nginx site configuration for a reverse proxy.

This script creates a new Nginx site configuration file for a reverse proxy. It also creates a symbolic link to the configuration file in the sites-enabled directory and reloads Nginx to apply the changes.

The script takes three arguments:

  1. The domain name (e.g., example.com)
  2. The URL of the backend server (e.g., http://localhost:3000)
  3. The port number (optional, default is 80)

Deploying a new Nginx site configuration for a reverse proxy with SSL.

This script creates a new Nginx site configuration file for a reverse proxy with SSL. It also creates a symbolic link to the configuration file in the sites-enabled directory and reloads Nginx to apply the changes.

The script takes four arguments:

  1. The domain name (e.g., example.com)
  2. The URL of the backend server (e.g., http://localhost:3000)
  3. The path to the SSL certificate (e.g., /path/to/cert.pem)
  4. The path to the SSL key (e.g., /path/to/key.pem)
  5. The port number (optional, default is 443)

Updating NGINX static site with rollback and change in port if needed

This script updates an existing Nginx static site configuration. It allows you to change the port and the directory containing the static files. The script also creates a backup of the existing configuration before making any changes.

It takes three arguments:

  1. The domain name (e.g., example.com)
  2. The path to the new directory containing the static files (e.g., /path/to/new/dist)
  3. The new port number (optional, default is 80)

To use the script:

Make it executable:

bash
chmod +x update-static-site-nginx.sh

Run it with necessary parameters:

bash
sudo ./update-static-site-nginx.sh -n mysite -d /path/to/new/dist

sudo ./update-static-site-nginx.sh -n hemap -d /home/kelly/ws/k6/nasu/src/hemap/dist

Or with port update:

bash
sudo ./update-static-site-nginx.sh -n mysite -p 8081 -d /path/to/new/dist

Parameters:

  1. The domain name (e.g., example.com)
  2. The path to the new directory containing the static files (e.g., /path/to/new/dist/files)
  3. The new port number (optional, default is 80)