多端口實(shí)現(xiàn)多站點(diǎn)的方法

前言

之前已經(jīng)在多網(wǎng)站搭建中用多域名的方式實(shí)現(xiàn)了多網(wǎng)站的搭建,這次簡單記錄下在沒有域名時(shí),使用多端口實(shí)現(xiàn)多站點(diǎn)搭建的辦法

環(huán)境

  • Ubuntu 12.04 LTS
  • PHP
  • Apache2
  • Mysql

需求

文件目錄
  • Wordpress:site.com/public
  • discuz: bbs/public
端口
  • Wordpress: ip:8080
  • discuz: ip:80

實(shí)現(xiàn)

配置文件在 /etc/apache2

ports.conf

NameVirtualHost *:80
Listen 80
Listen 8080
  • NameVirtualHost:指定服務(wù)器IP地址(和可能的端口)來使主機(jī)接受請求
  • * 表示任一服務(wù)器IP
  • 開啟對8080端口的偵聽

./sites-available/site.com.conf

wordpress 虛擬主機(jī)配置文件

<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 虛擬主機(jī)配置文件

<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更改默認(rèn)端口
在wordpress的后臺中,在General Settings里,將網(wǎng)站url加上端口8080

小tips

  • 之前修改端口配置后,怎么都搞不定,后檢查log文件,發(fā)現(xiàn)訪問8080端口時(shí),確實(shí)訪問到了wordpress目錄,只是后來跳轉(zhuǎn)到了discuz目錄,所以確定是wordpress的默認(rèn)端口80導(dǎo)致的跳轉(zhuǎn)。

  • 修改wordpress的默認(rèn)端口后,多端口訪問多站點(diǎn)功能成功實(shí)現(xiàn)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容