前言
之前已经在多网站搭建中用多域名的方式实现了多网站的搭建,这次简单记录下在没有域名时,使用多端口实现多站点搭建的办法
环境
- Ubuntu 12.04 LTS
- PHP
- Apache2
- Mysql
需求
文件目录
- Wordpress:site.com/public
- discuz: bbs/public
端口
- Wordpress: ip:8080
- discuz: ip:80
实现
配置文件在 /etc/apache2
ports.conf
NameVirtualHost *:80
Listen 80
Listen 8080
- NameVirtualHost:指定服务器IP地址(和可能的端口)来使主机接受请求
- * 表示任一服务器IP
- 开启对8080端口的侦听
./sites-available/site.com.conf
wordpress 虚拟主机配置文件
<VirtualHost *:8080>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin email
ServerName blog#没有域名,随便填
ServerAlias blog#同上
# 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>
- DocumentRoot:wordpress存放目录
- 以8080端口的请求使用此配置文件
./sites-available/bbs.conf
bbs 虚拟主机配置文件
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin email
ServerName bbs
ServerAlias bbs
# 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>
wordpress更改默认端口
在wordpress的后台中,在General Settings里,将网站url加上端口8080
小tips
之前修改端口配置后,怎么都搞不定,后检查log文件,发现访问8080端口时,确实访问到了wordpress目录,只是后来跳转到了discuz目录,所以确定是wordpress的默认端口80导致的跳转。
修改wordpress的默认端口后,多端口访问多站点功能成功实现