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:
- Create the necessary directory structure
- Copy your static files to the web server directory
- Create and enable the Nginx configuration
- Set appropriate permissions
- Restart Nginx to apply the changes
Example usage:
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 1Parameters:
- The domain name (e.g., example.com)
- The path to the directory containing the static files (e.g., /path/to/dist/files)
- 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:
- The domain name (e.g.,
example.com) - The path to the directory containing the static files (e.g.,
/path/to/dist/files) - The port number (optional, default is 80)
Make it executable:
chmod +x create-nginx-site.shRun it with sudo:
sudo ./create-nginx-site.sh example.com /path/to/dist/files 8080For subdomains, the port is optional:
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.comDeploying 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:
- The domain name (e.g., example.com)
- The URL of the backend server (e.g.,
http://localhost:3000) - 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:
- The domain name (e.g.,
example.com) - The URL of the backend server (e.g.,
http://localhost:3000) - The path to the SSL certificate (e.g., /path/to/cert.pem)
- The path to the SSL key (e.g., /path/to/key.pem)
- 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:
- The domain name (e.g.,
example.com) - The path to the new directory containing the static files (e.g.,
/path/to/new/dist) - The new port number (optional, default is 80)
To use the script:
Make it executable:
chmod +x update-static-site-nginx.shRun it with necessary parameters:
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/distOr with port update:
sudo ./update-static-site-nginx.sh -n mysite -p 8081 -d /path/to/new/distParameters:
- The domain name (e.g.,
example.com) - The path to the new directory containing the static files (e.g.,
/path/to/new/dist/files) - The new port number (optional, default is 80)