macOS --- 配置基於域名的虛擬主機

  1. 在終端運行 sudo vi /Applications/XAMPP/xamppfiles/etc/httpd.conf,打開apache配置文件。

在httpd.conf中找到"#Include /private/etc/apache2/extra/httpd-vhosts.conf",去掉全面的」#」,保存並退出。php

  1. 重啓XAMPP apache後就開啓了虛擬主機配置功能。
    運行sudo vi /Applications/XAMPP/xamppfiles/etc/apache2/extra/httpd-vhosts.conf,打開配置虛擬主機文件httpd-vhost.conf,配置虛擬主機。
    增長以下配置
<VirtualHost *:80>
    //設置域名根目錄
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/new_Project"
    //域名
    ServerName www.zhyunfe.com
    //錯誤日誌
    ErrorLog "/Applications/XAMPP/xamppfiles/htdocs/php_test_1/test_error_log"
    //經常使用日誌
    CustomLog "/Applications/XAMPP/xamppfiles/htdocs/php_test_1/test_access_log" common
</VirtualHost>

保存退出,並重啓apache。apache

  1. 將虛擬機地址添加到本機環境中的虛擬配置文件中

運行sudo vi /etc/hosts,打開hosts配置文件,加入」127.0.0.1 www.zhyunfe.com」,這樣就能夠配置完成www.zhyunfe.com虛擬機了。日誌

相關文章
相關標籤/搜索