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地址

相关文章
相关标签/搜索