环境
- Ubuntu 12.04 LTS
- PHP
- Apache2
- Mysql
需求
文件目录
- Wordpress:site.com/public
- discuz: bbs/public
域名
- Wordpress: site.com
- discuz: bbs.site.com、server ip
DNS
- site.com: server ip
- bbs.site.com: server ip
实现
配置文件在 /etc/apache2
ports.conf
NameVirtualHost *:80
Listen 80
- NameVirtualHost:指定服务器IP地址(和可能的端口)来使主机接受请求
- * 表示任一服务器IP
- 指定端口方便日后使用多端口作其他服务
./sites-available/site.com.conf
wordpress 虚拟主机配置文件
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin email
ServerName www.site.com
ServerAlias site.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/user/public/site.com/public
# Log file locations
LogLevel warn
ErrorLog /home/user/public/site.com/log/error.log
CustomLog /home/user/public/site.com/log/access.log combined
</VirtualHost>
- ServerName:以site.com访问时,访问的该文件配置的根目录中存放的网站
- DocumentRoot:wordpress存放目录
./sites-available/bbs.conf
bbs 虚拟主机配置文件
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin email
ServerName bbs.site.com
ServerAlias bbs.site.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/user/public/bbs/public
# Log file locations
LogLevel warn
ErrorLog /home/user/public/bbs/log/error.log
CustomLog /home/user/public/bbs/log/access.log combined
</VirtualHost>
** 当一个请求到达的时候,服务器会首先检查它是否使用了一个能和NameVirtualHost相匹配的IP地址。如果能够匹配,它就会查找每个与这个IP地址相对应的<VirtualHost>段,并尝试找出一个与请求的主机名相同的ServerName或ServerAlias配置项。如果找到了,它就会使用这个服务器。否则,将使用符合这个IP地址的第一个列出的虚拟主机。**
网友评论