Python 3.10
and above is required
sudo apt-get install python3
Nginx
must be installed
sudo apt-get install nginx
This file will be read by the python script and parsed, with each $name
key being another server.
Replace $variable
with your information.
{
"$name": {
"directory": "$directory",
"script": "$script",
"domains": "$domains"
}
}
$name
- The short name that will be used to make the service and proxy$directory
- The working directory of the website
Note: Please set this value to the absoute path of the directory
$script
- The script that will be ran in order to host the website
Note: You must add a
port
option and set the value to{port}
. This will later be dynamically formatted
$domains
- The domains that your website will be published on
Note: for the domains to work, you must point an
A
record to the ip address of your server
This will recursively go through your local config.json
file, and set up each key as a systemd unit
and nginx proxy
sudo python3 main.py
Note: Because this file will modify files within the
/etc/
directory, the file must run as root, the script being ran withsudo
Will execute the main script and apply
The main.py
script will iterate through every server config and sets up each config.
{
"example": {
"directory": "/home/ubuntu/example/dist",
"script": "/usr/bin/npx http-server --port {port}",
"domains": ["example.com", "www.example.com"]
}
}
- The script will create a file in
/etc/systemd/system/
namedexample.service
with content
[Unit]
Description=Start example server
After=network-online.target
Requires=network-online.target
[Service]
Type=simple
RemainAfterExit=yes
ExecStartPre=sleep 5
ExecStartPre=/usr/bin/git stash
ExecStartPre=/usr/bin/git pull
ExecStart=/usr/bin/npx http-server --port 5000
WorkingDirectory=/home/ubuntu/example/dist
User=ubuntu
[Install]
WantedBy=multi-user.target
- This service will be enabled and started with the commands
sudo systemctl enable example.service
sudo systemctl start example.service
- Next, the proxy will be created in
/etc/nginx/sites-available
with this content
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
location / {
proxy_pass http://127.0.0.1:5000;
include proxy_params;
}
}
- This will then be symlinked to
/etc/nginx/sites-enabled
with the command
sudo ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled`
- The proxy will then be enabled with
sudo systemctl restart nginx.service