How to deploy a website with HTTPS using serve
News
Apply for the SSL certificate of Let's encrypt, and forward the traffic of port 80 to port 443 (serve as the server) through nginx
This article is original, reproduced please indicate the source
SSL Certificate
Use a free SSL certificate from Let's encrypt. Visit https://certbot.eff.org and follow the prompts to obtain the certificate.
serve
installation
shell
sudo apt install npm
sudo npm install -g n
sudo n stable
sudo npm install -g serve
Start up
Can be skipped for testing only
shell
sudo nohup serve -C -p 443 --ssl-key /etc/letsencrypt/live/docs.monody.net/privkey.pem --ssl-cert /etc/letsencrypt/live/docs.monody.net/fullchain.pem & disown
Register System Service
Write service file
shell
sudo vim /etc/systemd/system/docs_monody.service
txt
[Unit]
Description=docs.monody.net
After=network.target
[Service]
ExecStart=/usr/local/bin/serve -C -p 443 --ssl-key /etc/letsencrypt/live/docs.monody.net/privkey.pem --ssl-cert /etc/letsencrypt/live/docs.monody.net/fullchain.pem FILEPATH //[!code focus]
WorkingDirectory=FILEPATH //[!code focus]
User=root
Group=root
# Restart the service when the program crashes
Restart=always
RestartSec=3
[Install]
WantedBy=default.target
Configuration
shell
sudo systemctl daemon-reload
sudo systemctl enable docs_monody
Test
txt
#restart test
sudo systemctl status docs_monody
● docs_monody.service - docs.monody.net
Loaded: loaded (/etc/systemd/system/docs_monody.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-05-24 09:52:22 UTC; 1min 31s ago
Main PID: 500 (node)
Tasks: 11 (limit: 1143)
Memory: 80.8M
CPU: 786ms
Now it's https website😀