当前位置: 首页 > 后端技术 > PHP

MacOS下XAMPP配置基于域名的虚拟主机

时间:2023-03-29 17:31:53 PHP

第一步打开MAC的/Applications/XAMPP/xamppfiles/etc中的httpd.conf文件。然后搜索httpd-vhosts.conf,去掉前面的#注释符号。第二步,在MAC上打开/Applications/XAMPP/xamppfiles/etc/extra打开httpd-vhosts.conf文件。打开配置虚拟主机的文件httpd-vhost.conf后,就可以配置自己需要的虚拟主机了。请注意,该文件默认打开两个虚拟主机作为示例。这两个虚拟主机不存在。只需在每一行前加#并注释掉,方便参考,避免其他问题。ServerAdminwebmaster@dummy-host.example.comDocumentRoot"/usr/docs/dummy-host.example.com"ServerNamedummy-host.example.comErrorLog"/private/var/log/apache2/dummy-host.example.com-error_log"CustomLog"/private/var/log/apache2/dummy-host.example.com-access_log"commonServerAdminwebmaster@dummy-host2.example.comDocumentRoot“/usr/docs/dummy-host2.example.com”ServerNamedummy-host2.example.comErrorLog“/private/var/log/apache2/dummy-host2.example.com-error_log”CustomLog“/private/var/log/apache2/dummy-host2.example.com-access_log"common添加如下配置ServerAdminnansong.comDocumentRoot"/Applications/XAMPP/xamppfiles/htdocs/0316/public"#OptionsIndexesFollowSymLinksExecCGI包括#don'tpermissionseelistOptionsAll#OptionsFollowSymLinksAllowOverrideallOrderallow,denyAllowfromallServerNamenansong.comServerAliaswww.nansong.comErrorLog"/Applications/XAMPP/xamppfiles/htdocs/0316/test_error_log"CustomLog"/Applications/XAMPP/xamppfiles/htdocs/0316/test_access_log"common说明:"OptionsAll"允许目录浏览,有安全隐患,适合个人调试程序。请注意,当站点根目录包含index.html页面时,该页面将默认打开。而不是一个目录列表,所以这个模式需要删除index.html。“OptionsIndexesFollowSymLinksExecCGIIncludes”不允许目录浏览,适合官方网站重启Apache如图第三步运行终端输入“sudovi/etc/hosts”打开Hosts配置文件,添加“127.0.0.1your.website.com"sudovi/etc/hosts打开vim编辑器需要使用的vim命令在命令模式下按i进入输入模式。在输入模式下按ESC进入命令行模式,按:q!如果您已经修改了文件并且不想保存它,请使用它!按:w!保存退出vim命令参考网址http://www.cnblogs.com/jeakon/archive/2012/08/13/2816802.htmlhttps://zh.wikibooks.org/zh-hans/Vim/%E4%B8%89%E7%A7%8D%E6%A8%A1%E5%BC%8F这样就可以配置站点虚拟主机,这样就可以使用“http://your.website.com”,其内容与“http://localhost/”一模一样,但存在无法访问localhost的问题。第四步,在/Applications/XAMPP/xamppfiles/etc/extra-vhosts.conf文件中再次打开httpd。添加DocumentRoot"/Applications/XAMPP/xamppfiles/htdocs/"ServerNamelocalhost修改完成后,再次进行第三步,将localhost指向127.0.0.1地址