多项目部署
本文档介绍如何在同一服务器上部署多个项目。
虚拟主机配置
Nginx 配置
在 Nginx 中为每个项目创建独立的虚拟主机配置文件:
nginx
server {
listen 80;
server_name project1.example.com;
root /www/wwwroot/project1;
index index.php index.html index.htm;
# 伪静态规则
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}Apache 配置
创建虚拟主机配置文件:
apache
<VirtualHost *:80>
ServerName project2.example.com
DocumentRoot /var/www/project2
<Directory /var/www/project2>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/project2-error.log
CustomLog ${APACHE_LOG_DIR}/project2-access.log combined
</VirtualHost>数据库分离
- 为每个项目创建独立的数据库
- 创建不同的数据库用户,分别授予对应数据库的权限
- 避免使用默认端口,提高安全性
目录结构建议
/www/
├── wwwroot/
│ ├── project1/ # 项目1
│ ├── project2/ # 项目2
│ └── project3/ # 项目3
├── backup/ # 备份目录
└── logs/ # 日志目录注意事项
- 确保各项目端口不冲突
- 为不同项目配置不同的 PHP 版本(如有需要)
- 配置独立的日志文件,便于问题排查
- 考虑使用 Docker 等容器化技术进行隔离部署