原文地址:https://lala.im/6897.html,請支持原作者!該處僅作轉載。
随着COVID-19的世界大流行,Gayhub上面也陆陆续续有很多关于这个病毒的有趣项目了。。
这是我搭建的一个演示站:https://covid19.233.fi/(24h删除)
以下步骤使用Debian10操作,首先安装curl/git/nginx/certbot/nodejs:
apt -y update
apt -y install build-essential curl git nginx python-certbot-nginx
curl -sL https://deb.nodesource.com/setup_14.x | bash -
apt -y install nodejs
拉取项目源码:
cd /opt
git clone https://github.com/sorxrob/covid3d.git
cd covid3d
编辑如下文件:
nano /opt/covid3d/src/constants.js
将CASES_API这段代码修改为下面的样子(自己准备一个域名)
export const CASES_API =
'https://covid19-api.233.fi';
如图所示:
安装前端依赖并构建资源用于生产:
npm install
npm run build
安装后端依赖:
cd backend
npm install
新建一个systemd服务用于守护后端:
nano /lib/systemd/system/covid19-api.service
写入如下配置:
[Unit]
Description=Covide19 API Service
After=network.target
[Service]
WorkingDirectory=/opt/covid3d/backend
ExecStart=/usr/bin/npm start
Restart=on-failure
User=root
[Install]
WantedBy=multi-user.target
启动后端:
systemctl start covid19-api.service
新建用于前端的nginx配置文件:
nano /etc/nginx/conf.d/covid19.conf
写入如下配置:
server {
listen 80;
server_name covid19.233.fi; # 换成你的域名
index index.html;
root /opt/covid3d/dist;
client_max_body_size 128G;
}
新建用于反代后端的nginx配置文件:
nano /etc/nginx/conf.d/covid19-api.conf
写入如下配置:
server {
listen 80;
server_name covid19-api.233.fi; # 换成你的域名
location / {
proxy_pass http://178.170.68.186:3030; # 换成你的服务器公网IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
使用certbot签发SSL证书:
certbot --nginx --agree-tos --no-eff-email --email [email protected]
最后设置nginx和covid19-api开机自启:
systemctl enable nginx covid19-api
演示: