MacOS 下 XAMPP配置基於域名的虛擬主機

第一步

在 MAC 的 /Applications/XAMPP/xamppfiles/etc 打開 httpd.conf 文件.html

而後搜索 httpd-vhosts.conf 去掉前邊的 # 註釋符號web

圖片描述

第二步

在 MAC 的 /Applications/XAMPP/xamppfiles/etc/extra 打開 httpd-vhosts.conf 文件.
打開了配置虛擬主機的文件 httpd-vhost.conf 後就能夠配置你須要的虛擬主機了。注意的是該文件默認開啓了兩個做爲例子的虛擬主機apache

這兩個虛擬主機是不存在的,它們每行前面加上#,註釋掉就行了,這樣既能參考又避免致使其餘問題。vim

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>

增長以下配置安全

<VirtualHost *:80>
    ServerAdmin nansong.com
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/0316/public"

    <Directory "/Applications/XAMPP/xamppfiles/htdocs/0316/public">
        #Options Indexes FollowSymLinks ExecCGI Includes #don't permission see list
        Options All
        #Options FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
    ServerName nansong.com
    ServerAlias www.nansong.com
    ErrorLog "/Applications/XAMPP/xamppfiles/htdocs/0316/test_error_log"
    CustomLog "/Applications/XAMPP/xamppfiles/htdocs/0316/test_access_log" common
</VirtualHost>

說明:
「Options All」是容許目錄瀏覽,有安全性風險,適合用於我的調試程序,需注意當站點根目錄含index.html頁面時,會默認打開網頁,而不是目錄列表,所以此模式需刪除index.html.
「Options Indexes FollowSymLinks ExecCGI Includes」是不容許目錄瀏覽,適合正式站點編輯器

如圖
圖片描述
重啓Apache。ide

第三步

運行終端 輸入 「sudo vi /etc/hosts」,打開hosts配置文件,加入」127.0.0.1 your.website.com「spa

sudo vi /etc/hosts

打開的是 vim 編輯器命令行

須要用到的 vim 命令
命令模式下按下 i 就進入了輸入模式。
在輸入模式按 ESC 就進入 命令行模式
按:q! 若曾修改過文件,又不想存儲,使用!爲強制離開不存儲文件
按:w! 保存並退出
vim命令參考網址
http://www.cnblogs.com/jeakon/archive/2012/08/13/2816802.html
https://zh.wikibooks.org/zh-hans/Vim/%E4%B8%89%E7%A7%8D%E6%A8%A1%E5%BC%8F

圖片描述

這樣就能夠配置完成sites虛擬主機了,這樣就能夠用 「http://your.website.com」 訪問了,
其內容和 「http://localhost/」 徹底一致
可是會有一點問題就是 localhost 沒法訪問了調試

第四步

咱們再次在 MAC 的 /Applications/XAMPP/xamppfiles/etc/extra 打開 httpd-vhosts.conf 文件.
添加

<VirtualHost *:80>
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/"
    ServerName localhost
</VirtualHost>

圖片描述

修改完成後再次進行第三步,將localhost指向127.0.0.1地址

相關文章
相關標籤/搜索