外卖系统安装说明书
本说明适用于本外卖点餐系统的完整部署,包含服务端(Golang)、客户端(Vue3 H5)和后台管理端(PHP 5.6)。
一、系统结构概览
本系统包含 3 个子系统:
- 服务端:Golang 开发,监听 9100 端口,通过 Nginx 代理为
api.xxx.com
- 客户端:Vue3 + Vite 构建的 H5 应用,部署为
www.xxx.com
- 后台管理端:PHP 5.6 开发,部署为
admin.xxx.com
二、服务端部署(Golang)
1. 环境要求
- Linux 系统
- Supervisor(用于守护进程)
- Nginx(用于反向代理)
- MySQL、Redis 数据库服务
2. 数据库准备
- 创建数据库:
orderfoodh5
- 导入初始化 SQL 文件(如 init_db.sql)
3. 将 api 上传至服务器 /var/www/html/api
,并配置文件 conf.ini(JSON 格式)
请修改 /var/www/html/api
权限为可写可执行
请修改 conf.ini 文件中的内容如下,替换为你的数据库与 Redis 配置:
{
"Db": {
"Driver": "mysql",
"Host": "你的数据库地址,例如 127.0.0.1 或公网地址",
"Name": "数据库名称,例如 orderfoodh5",
"User": "数据库用户名,例如 root",
"Password": "数据库密码,例如 yourpassword",
"Port": "3306",
"Charset": "utf8"
},
"Cache": {
"Driver": "redis",
"Host": "Redis 地址,例如 127.0.0.1",
"Num": "0",
"Port": "6379",
"Auth": "Redis 密码,如果没有可为空字符串"
},
"Conf": {
"Name": "项目名称,例如 ofH5",
"Host": "服务端监听地址,通常为 127.0.0.1",
"Port": "9100", // 服务端监听端口,默认 9100
"Secret": "f8dd1dfac2db6f2a395eb4ee0b5b7dc5", // 接口加密密钥,请保持复杂度,下面客户端和后台端都保持一致"
"Mode": "Dev" // 可选值:Dev(开发模式)或 Release(生产模式)
}
}
4. 使用 Supervisor 管理 Golang 服务
创建文件 /etc/supervisor/conf.d/orderFood.conf
,内容如下:
[program:orderFood]
directory=/var/www/html/api
command=/home/www/server/orderFood
autostart=true
autorestart=true
stderr_logfile=/var/log/orderFood.err.log
stdout_logfile=/var/log/orderFood.out.log
执行命令:
supervisorctl reread
supervisorctl update
supervisorctl start orderFood
5. 配置 Nginx(服务端代理)
server {
listen 443 ssl;
server_name api.xxx.com;
ssl_certificate /etc/ssl/server.crt;
ssl_certificate_key /etc/ssl/server.key;
location / {
proxy_pass http://127.0.0.1:9100;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
三、客户端部署(Vue3 H5)
1. 将 dist 上传至服务器 /var/www/html/dist
,并配置:
2. 客户端请求接口地址需指向 https://api.xxx.com
请修改 config.js 文件中的内容如下:
window._APP_CONFIG = {
VITE_APP_API_URL: "https://api.xxx.com", // 服务端地址
VITE_APP_CDN_URL: "https://api.xxx.com", // CDN加速地址
VITE_APP_API_SECRET: "f8dd1dfac2db6f2a395eb4ee0b5b7dc5",
VITE_APP_TIMEOUT: "5000",
VITE_APP_DEBUG_MODE: false,
VITE_APP_COLOR_PRIMARY: "#BB4040",
VITE_APP_COLOR_SECONDARY: "#6c757d",
VITE_APP_COLOR_SUCCESS: "#28a745",
VITE_APP_COLOR_DANGER: "#dc3545",
VITE_APP_COLOR_WARNING: "#ffc107",
VITE_APP_COLOR_INFO: "#17a2b8",
VITE_APP_COLOR_LIGHT: "#f8f9fa",
VITE_APP_COLOR_DARK: "#343a40",
VITE_APP_COLOR_MUTED: "#999",
VITE_APP_COLOR_WHITE: "#ffffff",
};
3. 使用 nginx 配置 www.xxx.com 网站
server {
listen 443 ssl;
server_name www.xxx.com;
ssl_certificate /etc/ssl/www.crt;
ssl_certificate_key /etc/ssl/www.key;
root /var/www/html/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
4. 若使用不同源,请开启 CORS 跨域支持
四、后台管理端部署(PHP 5.6)
1. 环境准备
- 安装支持 PHP 5.6 的 LNMP 环境
- 上传后台代码至
/var/www/html/admin
- 上传文件夹给与写入权限
/var/www/html/admin/Public/Static/upload
- 修改配置文件 Lib/Config/Config.ini 配置连接信息
- 后台登录地址:https://admin.xxx.com
- 默认管理员账号:18888888888
- 默认管理员密码:123456
[Config]
ApiUrl='https://api.xxx.com'
CdnUrl='https://api.xxx.com'
Secret='f8dd1dfac2db6f2a395eb4ee0b5b7dc5'
Number='1.0.0'
2. 配置 Nginx(后台站点)
server {
listen 443 ssl;
server_name admin.xxx.com;
ssl_certificate /etc/ssl/admin.crt;
ssl_certificate_key /etc/ssl/admin.key;
root /var/www/html/admin/Public; #注意这里绑定的是目录下的Public文件夹
location / {
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
break;
}
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
五、常见问题(FAQ)
**Q1:数据库连接失败?
- 请检查 conf.ini 配置项是否填写正确
- 数据库服务是否已启动
- 防火墙是否开放 3306 端口
Q2:访问接口返回 502?
- Golang 程序可能未启动(检查 Supervisor 状态)
- Nginx 代理地址是否正确配置
Q3:如何申请 HTTPS 证书?
- 推荐使用 Let’s Encrypt 免费证书
- 也可使用阿里云、腾讯云的免费 SSL 服务
Q4:后台页面访问空白?
- 请确认服务器支持 PHP 5.6 并正确配置
- 检查文件权限是否足够
六、联系方式与支持
- 官网地址:https://www.codapp.cn/
- 客服邮箱:support@codapp.cn
感谢使用本系统!如有问题请联系技术支持。
Codapp外卖点餐系统安装说明书