基于 Docker 的个人服务器一键环境。
本项目的 DNMP 包含了以下容器:
- Nginx:负责反向代理所有容器站点,也可以运行静态站点,按需求配置
- Apache:负责运行静态和 PHP 站点
- PHP-FPM:负责运行 PHP 程序,同时支持运行 Swoole。
- MySQL & PostgreSQL:数据库
容器中服务的配置都存储于 service
文件夹中,数据都存储于 data
文件夹中,日志都存储于 logs
下,web/wwwroot
为网站目录,share
为所有容器中的共享目录,如果有需要在各容器中或宿主机**享文件或文件夹,可以存储于该文件夹。
- 先修改下
bin/dnmp
脚本内的DNMP_DIR
变量为你的 dnmp 目录。 - 然后在 dnmp 下运行
docker-compose up -d
或者运行bin/dnmp up
即可完成启动。
Apache 和 Nginx 配置使用 devilbox/vhost-gen,具体命令见下方:
- 创建静态站点(Nginx,HttpOnly)
bin/nginx-vg -p /data/wwwroot/<you_host> -n <you_host> -s
docker restart nginx
- 创建 PHP 站点(Apache,HttpOnly)
bin/apache-vg -p /data/wwwroot/<you_host> -n <you_host> -s
bin/nginx-vg -r http://apache:80 -n <you_host> -l / -s
docker restart apache
docker restart nginx
- 创建 Https 站点(Nginx,Https)
使用文件验证方法
# 先创建一个临时的 Http 站点用于申请 ssl 证书
bin/nginx-vg -p /data/wwwroot/<you_host> -n <you_host> -s
docker restart nginx
# 申请 ssl 证书(使用文件验证方法)
bin/acme --issue -d <you_host> --webroot /data/wwwroot/<you_host>
# 将站点升级为 Https
bin/nginx-vg -p /data/wwwroot/<you_host> -n <you_host> -s -m let
docker restart nginx
使用 DNS 验证方法(DNSPod 为例)
# 修改 .env 下的 DP_ID, DP_KEY 这是对应 DNS 提供商的 API,按 ACME 的文档进行设置
# 申请 ssl 证书
bin/acme --issue --dns dns_dp -d <you_host>
# 创建 Nginx 反代或者静态站点
bin/nginx-vg -p /data/wwwroot/lincdn.top -n lincdn.top -m let -s
bin/nginx-vg -r <proxy_url> -n <you_host> -m let -l / -s
docker restart nginx
- 创建 Https 站点(Apache,Https)
使用文件验证方法
# 先创建一个临时的 Http 站点用于申请 ssl 证书
bin/nginx-vg -p /data/wwwroot/<you_host> -n <you_host> -s
docker restart nginx
# 申请 ssl 证书(使用文件验证方法)
bin/acme --issue -d <you_host> --webroot /data/wwwroot/<you_host>
# 创建 Apache 站点
bin/apache-vg -p /data/wwwroot/<you_host> -n <you_host> -s -m let
# 将 Nginx 反代升级为 Https
bin/nginx-vg -r https://apache:443 -n <you_host> -l / -s -m let
docker restart apache
docker restart nginx
使用 DNS 验证方法(DNSPod 为例)
# 修改 .env 下的 DP_ID, DP_KEY 这是对应 DNS 提供商的 API,按 ACME 的文档进行设置
# 申请 ssl 证书
bin/acme --issue --dns dns_dp -d <you_host>
# 创建 Nginx 反代和 Apache 站点
bin/nginx-vg -r https://apache:443 -n <you_host> -m let -l / -s
bin/apache-vg -p /data/wwwroot/<you_host> -n <you_host> -m let -s
docker restart apache
docker restart nginx
数据库密码,各种服务的版本,PHP 插件等配置修改 .env
文件中的环境变量即可。
DNMP 启动后,我们可以很方便的添加额外的服务到 DNMP 网络中。在 apps
下一个 Portainer Docker 管理面板的案例,你可以参考该样例进行后续服务的添加。
# 请注意为所有需要加入 DNMP 网络的 docker-compose.yml 文件中都加入这些配置
networks:
default:
external:
name: dnmp
额外的容器启动后,我们可以到 NPM 中配置反向代理即可完成服务的添加。
docker-stack 由 Otstar Lin 和下列 贡献者 的帮助下撰写和维护。
Otstar Lin - Personal Website · Blog · Github
根据 MIT License 许可证开源。