这篇文章记录了从 0 开始搭建 oneman 环境的流程, 重点包括使用 aaPanel 与 Cloudflare 部署 FOSSBilling, 配置 Nginx 与数据库, 设置权限, 计划任务和 SMTP 邮件, 并补充了 LXDAPI 插件的基础对接步骤.
适合想快速完成账单面板部署, 并为后续接入 LXC 销售能力做准备的用户参考. (AI摘要总结)
前言
使用到的项目:
- FOSSBilling: FOSSBilling 起源于 BoxBilling,一个诞生于 2010 年代的老牌开源财务与客户管理系统(FOSSBilling的生态似乎很糟糕)
- lxdapi-web-server: 一个完整的 LXD 容器管理解决方案, 包含高性能 Go 后端服务和多种前端插件, 为主机商提供完整的 LXD 容器销售与管理功能.
教程
FOSSBilling
教程演示使用 aaPanel + Cloudflare.
安装 aaPanel
从官网获取安装命令. https://www.aapanel.com/new/download.html
1
| URL=https://www.aapanel.com/script/install_panel_en.sh && if [ -f /usr/bin/curl ];then curl -ksSO $URL ;else wget --no-check-certificate -O install_panel_en.sh $URL;fi;bash install_panel_en.sh ipssl
|
安装 Nginx, PHP 8.2 和 MySQL 8.0.
在 软件商店 页面, 选择 已安装, 点击 PHP82 旁的设置.
点击 安装扩展.
安装 opcache, imagemagick 和 bz2.
安装完成后(左上角进度跑完就是安装完成), 重启 PHP.
创建网站
在 网站 页面, 点击添加站点, 输入网站域名, PHP 版本选择 PHP 8.2, 并创建 MySQL 数据库.
进入网站目录, 下载 FOSSBilling 源码并解压.
1 2 3
| wget https://github.com/FOSSBilling/FOSSBilling/releases/download/0.7.2/FOSSBilling.zip apt install unzip -y unzip FOSSBilling.zip
|
删除压缩包
接下来配置文件夹和文件权限, 点击进入文件管理.
全选文件, 右键点击权限, 所有权改为 www, 权限设为 755, 然后点击申请.
点击网站站点名称, 进入配置页面.
参考文档 https://fossbilling.org/docs/getting-started/installation#nginx 修改 Nginx 配置.
先删掉宝塔默认创建的配置(这会影响宝塔面板功能, 例如 SSL 证书申请等).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| server { listen 80; server_name idc.qzq.im; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/idc.qzq.im; include /www/server/panel/vhost/nginx/extension/idc.qzq.im/*.conf;
- #SSL-START SSL related configuration, do NOT delete or modify the next line of commented-out 404 rules - #error_page 404/404.html; - #SSL-END - - #ERROR-PAGE-START Error page configuration, allowed to be commented, deleted or modified - error_page 404 /404.html; - error_page 502 /502.html; - #ERROR-PAGE-END - - #PHP-INFO-START PHP reference configuration, allowed to be commented, deleted or modified - include enable-php-72.conf; - #PHP-INFO-END - - #REWRITE-START URL rewrite rule reference, any modification will invalidate the rewrite rules set by the panel - include /www/server/panel/vhost/rewrite/idc.qzq.im.conf; - #REWRITE-END - - # Forbidden files or directories - location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md) - { - return 404; - } - - # Directory verification related settings for one-click application for SSL certificate - location ~ \.well-known{ - allow all; - } - - #Prohibit putting sensitive files in certificate verification directory - if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) { - return 403; - } - - location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ - { - expires 30d; - error_log /dev/null; - access_log /dev/null; - } - - location ~ .*\.(js|css)?$ - { - expires 12h; - error_log /dev/null; - access_log /dev/null; - } access_log /www/wwwlogs/idc.qzq.im.log; error_log /www/wwwlogs/idc.qzq.im.error.log; }
|
最后的内容如下.
1 2 3 4 5 6 7 8 9 10 11 12
| server { listen 80; server_name idc.qzq.im; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/idc.qzq.im; include /www/server/panel/vhost/nginx/extension/idc.qzq.im/*.conf;
access_log /www/wwwlogs/idc.qzq.im.log; error_log /www/wwwlogs/idc.qzq.im.error.log; }
|
添加以下配置.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| try_files $uri $uri/ @rewrite; sendfile off; # Block access to sensitive files location ~* .(ini|sh|inc|bak|twig|sql)$ { return 403; } # Block /vendor completely location ^~ /vendor/ { return 403; } # Block direct access to config.php location = /config.php { return 403; } # Block access to hidden files except .well-known location ~ /\.(?!well-known\/) { return 403; } # Disable PHP execution in /uploads location ~* /uploads/.*\.php$ { return 403; } # Deny access to /data, except /assets/gateways location ~* /data/(?!(assets/gateways/)) { return 403; } location @rewrite { rewrite ^/page/(.*)$ /index.php?_url=/custompages/$1; rewrite ^/(.*)$ /index.php?_url=/$1; } location ~ \.php { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/tmp/php-cgi-82.sock; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; include fastcgi_params; }
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { root /www/wwwroot/idc.qzq.im; # 替换成实际的网站目录 expires off; }
|
添加后的配置如下.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| server { listen 80; server_name idc.qzq.im; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/idc.qzq.im; include /www/server/panel/vhost/nginx/extension/idc.qzq.im/*.conf; + + try_files $uri $uri/ @rewrite; + sendfile off; + # Block access to sensitive files + location ~* .(ini|sh|inc|bak|twig|sql)$ { + return 403; + } + + # Block /vendor completely + location ^~ /vendor/ { + return 403; + } + + # Block direct access to config.php + location = /config.php { + return 403; + } + + # Block access to hidden files except .well-known + location ~ /\.(?!well-known\/) { + return 403; + } + + # Disable PHP execution in /uploads + location ~* /uploads/.*\.php$ { + return 403; + } + + # Deny access to /data, except /assets/gateways + location ~* /data/(?!(assets/gateways/)) { + return 403; + } + + location @rewrite { + rewrite ^/page/(.*)$ /index.php?_url=/custompages/$1; + rewrite ^/(.*)$ /index.php?_url=/$1; + } + + location ~ \.php { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:/tmp/php-cgi-82.sock; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_intercept_errors on; + include fastcgi_params; + } + + location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { + root /www/wwwroot/idc.qzq.im; # 替换成实际的网站目录 + expires off; + }
access_log /www/wwwlogs/idc.qzq.im.log; error_log /www/wwwlogs/idc.qzq.im.error.log; }
|
如果你的 PHP 版本不是 82, 在 /www/server/nginx/conf 目录找到对应 PHP 版本的配置文件, 查看 Unix Socket 路径.
在 Cloudflare 添加 DNS 记录, 类型选择 A, IPv4 地址填写服务器 IP, 如源站为 IPv6, 类型选择 AAAA.
在 SSL/TLS -> 概述 中, 将 SSL/TLS 加密模式修改为灵活.
安装 FOSSBilling
访问 https://域名 安装 FOSSBilling.
在 aaPanel 面板的数据库页面查看数据库连接信息, 填写数据库信息.
设置管理员名称, 邮箱和密码. 后续将使用这里设置的邮箱和密码登录后台.
配置默认货币, 保持默认即可, 随后点击 Install 开始安装.
出现如下页面, 代表 FOSSBilling 已安装完成. 接下来删除 Install 目录(一般情况下会默认删除), 并设置配置文件权限, 创建计划任务.
删除 Install 目录
使用 ls 命令看看有没有 install 目录. 如果有 install, 执行第一条命令; 如果和下方一样, 没有 install 目录, 则不需要执行.
1 2 3 4
| root@ser262811688987:/www/wwwroot/idc.qzq.im# ls config.php console.php data index.php library load.php modules rewrite-missing.html themes config-sample.php cron.php di.php ipn.php LICENSE locale README.md robots.txt vendor root@ser262811688987:/www/wwwroot/idc.qzq.im#
|
修改配置文件权限
执行第二条命令, 将配置文件权限设置为只读.
添加定时任务
接下来, 使用宝塔计划任务创建一个每五分钟执行一次的定时任务.
在 计划任务 页面, 点击添加任务.
复制后半段命令填入脚本内容.
参考下图填写.
执行一次试试.
正常运行.
接下来访问 https://域名/admin/staff/login, 就可以登录后台了.
邮件
提示
这里有一个小坑, 多数邮件服务会要求 SMTP 发信的用户名和发件人一致, 需要在 设置->系统设置 中配置邮箱
如上面两张图, 这两个邮箱要一样, 才能正常使用 SMTP 发信.
LXDAPI
安装 LXDAPI 对接插件
下载 https://github.com/xkatld/lxdapi-web-server/archive/refs/heads/main-stable.zip 并解压后, 提取出 fossbilling 文件夹. 将 fossbilling 文件夹上传到 /modules 目录.
启用插件.
剩下的内容参考 官方文档. 目前 Alice 炸了, 创建不了 VPS, 以后再写.