Flutter web的部署depoly & FTP & apache & Node js

本文档详述了如何将Flutter应用构建为Web版本,并在Ubuntu服务器上部署,包括通过FTP传输文件、使用Apache2服务器和Node.js运行应用。还解决了FTP连接、权限和端口配置等问题,确保应用正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主要命令

flutter build web
sudo systemctl restart apache2
node app.js

PS

如果你用的是ubuntu (我用的是Ubuntu,习惯了)

  • 教程中的httpd,要用apache2
  • service 要用systemctl

部署步骤简述:

  1. build flutter
  2. 服务器 Ftp,
    • 向服务器copy flutter build之后的文件
    • 其实我感觉用Git,然后通过GitHub上的私有仓库,可以更方便的实现效果
  3. 部署Flutter
  4. 安装apache
    • 更改端口 (避开已被占用的 80端口,我80端口是有用的。)
  5. 安装node npm

详细步骤

1.build flutter

  1. 运行命令 build flutter web

2.搭建FTP

1. 服务端安装部署 ftp服务

这是为了copy flutter build出的问题,当然你也可以通过 git、ssh,能传到指定目录就行。

sudo apt install vsftpd

service vsftpd start
service vsftpd restart

systemctl restart vsftpd.service
systemctl status -l vsftpd.service

Ftp遇到的问题

1. 端口异常
  • 21端口检查
    - telnet localhost 21(测试是否为端口问题)
    - netstat -tulpn | grep :21

让 防火墙允许21端口传输

iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
  • 登录不上:
    • service上要安装 vsftpd
    • 查看 ftp 服务器运行状态 systemctl status -l vsftpd.service
2. File Zila 连接报错(但命令行,以起效)

报错 pam_unix(vsftpd:auth): Couldn’t open /etc/securetty: No such file or directory

响应: 	220 (vsFTPd 3.0.3)
命令: 	AUTH TLS
错误: 	20 秒后无活动,连接超时
错误: 	无法连接到服务器

pam_unix(vsftpd:auth): authentication failure; logname= uid=0 euid=0 tty=ftp ruser=anonymous rhos>
  • 解决办法 sudo cp /usr/share/doc/util-linux/examples/securetty /etc/securetty
3. 上传文件异常
550 Permission denied 

配置文件,默认不允许上传,反注解设置

write_enable=YES

3.部署Flutter

  • 复制build/web 下所有文件,到服务器的 /var/www/html/你的ip地址/public-flutter
    • public-flutter是我自己建造的
    • 复制,采用FileZila软件直接拖拽
  • 新建和node.js 相关的文件
    • 在 /var/www/html/你的ip地址/ 中新建2个文件 (app.js, package.json)
创建的文件

/var/www/html/你的ip地址/app.js文件

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public-flutter')));


module.exports = app;

package.json 文件

{
  "name": "my_routine_app",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "cookie-parser": "^1.4.5",
    "debug": "~2.6.9",
    "express": "^4.16.4",
    "morgan": "^1.9.1"
  }
}

Apache

教程

如果你用的是ubuntu

  • 教程中的httpd,要用apache2
  • service 要用systemctl
更换port
  1. 更换port
  • CentOS/Fedora:
    • $ sudo vi /etc/httpd/conf/httpd.conf
  • Ubuntu/Debian:
    • $ sudo vi /etc/apache2/ports.conf
  1. 更换Virtual

If you have configured virtual host for your website (e.g www.mysite.com) at /etc/apache2/sites-enabled/mysite.conf then you can open that file instead.

$ sudo vi /etc/apache2/sites-enabled/mysite.conf
# Otherwise, open the default virtual host configuration file at

$ sudo vi /etc/apache2/sites-enabled/000-default.conf
重启
$ sudo systemctl restart apache2 #SystemD系统
$ sudo service apache2 restart #SysVInit系统

问题

  1. 无法打开
    AH00558: apache2: Could not reliably determine the server’s fully qualified dom
sudo vi /etc/apache2/sites-enabled/000-default.conf
# 范注解 ServerName,填写自己的host

ServerName my.albertsnow.xyz
  1. 无法打开网址
    用http协议试试

  2. Forbidden – You don’t have permission to access

# **** 换成你的地址, 我是这个就ok了
 sudo chmod -R 775 /var/www/html/****
# 这个我没用
 sudo chown -R user:group /path/to/webroot/directory
# 重启
sudo systemctl restart apache2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值