部署
约 915 字大约 3 分钟
2025-03-29
本文档适用于部署 Astral3D 编辑器到服务器上。
以Golang版本后端为例,其他语言版本后端部署方式请参考官方文档。
本地打包
前端打包
# 确认 Node.js 版本(≥ 18.x)
node -v
# 拉取代码
git clone https://github.com/mlt131220/Astral3DEditor.git
# 安装依赖
cd Astral3DEditor
yarn install
# 打包前端代码
yarn build
后端打包
# 确认go环境
go version
# 拉取代码
git clone https://github.com/mlt131220/Astral3DEditorGoBack.git
# 安装依赖
go mod tidy
# 修改数据库等配置(修改 conf/app.conf,详见 https://github.com/mlt131220/Astral3DEditorGoBack/blob/main/README.md)
edit conf/app.conf
# 安装bee工具
go get -u github.com/beego/bee/v2
# 编译后端代码
# Linux
bee pack -be GOOS=linux -be GOARCH=amd64
# Windows
bee pack -be GOOS=windows
服务器部署(Windows)
基础环境
或者直接使用集成环境,如PHPStudy。
前端部署
将前端打包后的文件放到方便读取的目录下,如 C:\www\Astral3dEditor
;
后端部署
- 将后端编译后的文件放到方便读取的目录下,如
C:\www\Astral3DEditorGoBack
; - 打开 MySQL 数据库,创建名为
astral3d
的数据库,并导入Astral3DEditorGoBack/static/sql/astral-3d-editor.sql
文件; - 启动 MySQL 服务,并确保 MySQL 服务正常运行;
- 双击后端程序打包生成的可执行文件
Astral3DEditorGoBack.exe
启动后端服务,默认监听8080
端口;
Nginx 配置
- 打开 Nginx 配置文件,假设nginx安装目录为
C:\nginx
,则配置文件路径为C:\nginx\conf\nginx.conf
; - 在
http
块中添加以下配置:http { # ... 忽略原有其他配置不变更 # 开启gzip gzip on; # 导入所有的server配置 include vhosts/*.conf; }
- 在
C:\nginx\conf
目录下创建vhosts
目录(与上方http中增加的配置路径同名,并非一定要为vhost
,可以自定义); - 在
C:\nginx\conf\vhosts
目录下创建astral3d.conf
文件,内容如下:server { # 监听端口,即前端部署的端口,一般设置为80 listen 80; # 域名/ip/localhost server_name 127.0.0.1; # 访问 server_name:listen 后,请求就会被转发到这个location块中 location / { # 前端部署的目录,即前端打包后的文件所在目录 root "C:\www\Astral3dEditor"; # 文件url重写规则,将请求转发到index.html(单页面应用) try_files $uri $uri/ index.html; # 项目入口文件 index index.html; } # 后端api接口代理,接口请求匹配 /api 的会走此处转发,下面都同理 location /api { # 后端接口访问地址,上面部署在了本机的8080端口 proxy_pass http://127.0.0.1:8080/api; } # 前端websocket代理 location /socket { proxy_pass http://127.0.0.1:8080/api/sys/ws; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_connect_timeout 10s; proxy_read_timeout 300s; proxy_send_timeout 300s; } # 如果需要使用upyun上传功能,则需要添加以下配置 # 假设 http://upyun.xxx.com 为你的upyun存储 location /upyun { rewrite ^/upyun(.*)$ $1 break; proxy_pass http://upyun.xxx.com; } location /static/upload { proxy_pass http://upyun.xxx.com/static/upload; } location /static/bim2gltf { proxy_pass http://upyun.xxx.com/static/bim2gltf; } }
启动服务
nginx -s start
# 重启 nginx(如果修改了配置文件)
nginx -s reload
此时访问 http://127.0.0.1
即可访问到 Astral3D 编辑器。
服务器部署(Linux)
Docker 部署
注意事项
- 后端打包前请确认
Astral3DEditorGoBack/conf/app.conf
文件中的runmode = prod
; - 后端部署时,请确保 MySQL 数据库配置正确,并导入
Astral3DEditorGoBack/static/sql/astral-3d-editor.sql
文件; - 前端部署时,请确保 Nginx 配置正确,并将前端部署到服务器上;
- 后端部署时,请确保后端程序启动成功,并监听
Astral3DEditorGoBack/conf/app.conf
中配置的端口httpport
,默认为8080
; - 前端部署时,请确保前端程序启动成功,并监听 Nginx 配置中配置的端口,比如上面示例的
80
端口; - 部署完成后,请确保 Nginx 与 MySQL 服务正常运行;
- 部署完成后,请确保前端程序与后端程序正常运行;
版权所有
版权归属:千山我独行丶