安装 Nginx 并部署
bash
# 安装 Nginx
sudo apt update
sudo apt install nginx -y
bash
# 启动 Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
bash
# 确认安装成功
sudo systemctl status nginx
安装完成后,将构建好的 dist 目录内容部署到 Nginx 默认站点目录:
bash
# 清空默认站点目录(可选)
sudo rm -rf /var/www/html/*
bash
# 将 dist 内容复制到 Nginx 目录
sudo cp -r dist/* /var/www/html/
或者如果希望保留在自定义路径,可以配置虚拟主机
配置虚拟主机(可选):
bash
sudo nano /etc/nginx/sites-available/agent-platform
添加nginx配置:
bash
server {
listen 80;
server_name your-domain.com; # 替换为您的域名或IP
root /home/dmtvsoft/logservice/frontend/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
# 代理后端 API(如果后端在同一服务器)
location /api/ {
proxy_pass http://localhost:8000; # 后端服务地址
proxy_set_header Host $host;
}
}
启用配置并重启 Nginx:
bash
sudo ln -s /etc/nginx/sites-available/agent-platform /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx