MacApache配置虚拟主机

今天小编就为大家带来一篇Mac在自带apache配置虚拟主机的文章。小编觉得挺不错的,为此分享给大家做个参考。一起跟随小编过来看看吧。

创新互联建站是一家专业提供阿拉山口企业网站建设,专注与网站制作、成都网站设计H5技术、小程序制作等业务。10年已为阿拉山口众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

一、启动Apache

终端输入:sudo apachectl start

Apache的安装目录在:/etc/apache2/,etc默认是隐藏的。有三种方式查看:

1.桌面位于Finder时:shift+command+g,输入“/etc”(即Finder-前往-前往文件夹的快捷键)

2.打开终端:cd /etc

3.可以在terminal 输入 "open /etc"

二、设置虚拟主机

1.在终端运行“sudo vi /etc/apache2/httpd.conf”,打开Apche的配置文件

2.在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“#”,保存并退出。

3.运行“sudo apachectl restart”,重启Apache后就开启了虚拟主机配置功能。

4.运行“sudo vi /etc/apache2/extra/httpd-vhosts.conf”,就打开了配置虚拟主机文件httpd-vhost.conf,配置虚拟主机了。需要注意的是该文件默认开启了两个作为例子的虚拟主机

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

而实际上,这两个虚拟主机是不存在的,在没有配置任何其他虚拟主机时,可能会导致访问localhost时出现如下提示:
Forbidden
You don't have permission to access /index.php on this server

最简单的办法就是在它们每行前面加上#,注释掉就好了,这样既能参考又不导致其他问题。

5.增加如下配置,支持localhost访问,添加虚拟主机访问

 
DocumentRoot "/Library/WebServer/Documents" 
ServerName localhost 
ErrorLog "/private/var/log/apache2/localhost-error_log" 
CustomLog "/private/var/log/apache2/localhost-access_log" common 
 
 
DocumentRoot "/Library/WebServer/Documents" 
ServerName 虚拟主机地址 (如:www.test.com)
ErrorLog "/private/var/log/apache2/test-error_log" 
CustomLog "/private/var/log/apache2/test-access_log" common 
 
Options Indexes FollowSymLinks MultiViews 
AllowOverride None 
Order deny,allow 
Allow from all 
 

保存,退出,重启Apache。

6.运行“sudo vi /etc/hosts”,打开hosts配置文件,加入"127.0.0.1 www.test.com",这样就可以配置完成test虚拟主机了。

打开浏览器,输入:www.test.com

It works!

配置成功,和localhost一致!

看完上述内容,你们掌握Mac Apache配置虚拟主机的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


分享名称:MacApache配置虚拟主机
当前路径:http://bzwzjz.com/article/jiigec.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站建设费用 企业网站制作 成都网站设计公司 响应式网站设计 成都营销网站建设 响应式网站设计 企业网站建设公司 成都网站制作 网站设计 成都网站制作 定制网站设计 成都网站设计 成都网站制作 定制网站建设 成都网站设计 手机网站制作 重庆网站建设 app网站建设 专业网站建设 网站设计 泸州网站建设 成都模版网站建设