Apache 已安裝,需啟用虛擬主機配置文件。
編輯 Apache/conf/httpd.conf,搜尋:
Include conf/extra/httpd-vhosts.conf
確保行首無 # 註釋。同時取消 NameVirtualHost *:80 註釋。
編輯 Apache/conf/extra/httpd-vhosts.conf,在文件末尾添加:
<VirtualHost 127.0.0.1:80>
DocumentRoot "D:/ComsenzEXP/wwwroot"
ServerName www.moke8.com
ServerAlias *
DirectoryIndex index.htm index.php index.html
ErrorLog "logs/www_moke8_error.log"
CustomLog "logs/www_moke8_access.log" common
</VirtualHost>
<VirtualHost 127.0.0.2:80>
DocumentRoot "D:/ComsenzEXP/www"
ServerName moke8.com
ServerAlias *
DirectoryIndex index.htm index.php index.html
ErrorLog "logs/moke8_error.log"
CustomLog "logs/moke8_access.log" common
</VirtualHost>
關鍵點:
DocumentRoot:網站程式物理路徑(使用正斜線或雙反斜線)ServerName:主域名ServerAlias *:接受所有子域名/別名- 不同虛擬主機建議使用不同 IP(如 127.0.0.1 / 127.0.0.2)或同 IP 不同端口,避免衝突
- 日誌文件分離便於排查
C:\Windows\System32\drivers\etc\hosts 添加:
127.0.0.1 www.moke8.com
127.0.0.2 moke8.com
分別訪問 https://www.moke8.com、https://moke8.com,應正確指向對應目錄並加載 Discuz! 前台。
ServerAlias *,明確列出允許的域名,防止惡意解析綁定。