1. 该文的目的
本文记录在linux上部署flutter 编译的web程序。部署的前提为在linux中安装nginx。
2. flutter编译
flutter build web
执行该命令后,在工程的根目录的build目录下生成了web目录,将该目录所有内容压缩成zip传到服务器。在mac上可以使用scp /.../web.zip root@192.xx.xx.xx:/root/将文件传到服务器。
3,nginx的安装和部署
- 在linux上安装nginx。
sudo apt-get update
sudo apt-get install nginx
- 在
/etc/nginx/nginx.conf文件的http节点下增加server节点
server {
listen 80;#端口
server_name _;#下划线是通配符,表示所有内容都匹配。如果是域名则填写对应的域名即可。
location / {
root /root/web/;//指的静态资源放的位置,这里表示在根目录的web下面。
index index.html;
}
# 可以添加其他配置,例如 SSL 配置等
}
- 启动服务
sudo systemctl reload nginx
启动服务后就可以通过ip:prot进行访问了。
4. 其他注意事项
- 检查nginx的配置语法是否正确
sudo nginx -t
- 查看nginx错误日志
sudo cat /var/log/nginx/error.log
-
更新服务
- 将程序重新打包发送到服务器。
- 关闭nginx,解压替换掉之前的服务。
- 重启服务。
-
将上面的相关命令通过脚本的方式调用提高效率。
5. 资料
- 主要通过chatgpt进行辅助。