環(huán)境
- 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
實現(xiàn)
配置文件在 /etc/apache2
ports.conf
NameVirtualHost *:80
Listen 80
- NameVirtualHost:指定服務(wù)器IP地址(和可能的端口)來使主機接受請求
- * 表示任一服務(wù)器IP
- 指定端口方便日后使用多端口作其他服務(wù)
./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訪問時,訪問的該文件配置的根目錄中存放的網(wǎng)站
- 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>
** 當(dāng)一個請求到達(dá)的時候漠趁,服務(wù)器會首先檢查它是否使用了一個能和NameVirtualHost相匹配的IP地址羽资。如果能夠匹配棍丐,它就會查找每個與這個IP地址相對應(yīng)的<VirtualHost>段阔拳,并嘗試找出一個與請求的主機名相同的ServerName或ServerAlias配置項听盖。如果找到了曲楚,它就會使用這個服務(wù)器。否則贩疙,將使用符合這個IP地址的第一個列出的虛擬主機讹弯。**