一、启动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,配置虚拟主机了。需要注意的是该文件默认开启了两个作为例子的虚拟主机

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

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

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

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

<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
ErrorLog "/private/var/log/apache2/localhost-error_log"
CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost>
<VirtualHost *:80>
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
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

保存,退出,重启Apache。

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

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

It works!

配置成功,和localhost一致!

Mac配置虚拟主机的更多相关文章

  1. mac 配置虚拟主机

    http://www.upwqy.com/details/4.html 编辑httpd.conf文件,输入命令: vim /etc/apache2/httpd.conf 编辑httpd-vhosts. ...

  2. windows和mac下分别配置虚拟主机

    windows下配置 1.找到apache的配置文件,httpd.conf 2.找到 LoadModule rewrite_module modules/mod_rewrite.so 去掉前边的# 3 ...

  3. 转载:mac系统XAMPP配置虚拟主机

    安装完xampp后,想添加一个virsualhost,一直报错.查了半天资料,都是乱说,后来看到了一篇国外的文章,终于弄出来了,整理一下. 第一步,配置本地hosts sudo vi /etc/hos ...

  4. mac 上 mamp 配置虚拟主机 具体过程 ?

    https://www.zhihu.com/question/32320396 mac 上 mamp 配置虚拟主机 具体过程 ? 按照哪些配置什么的 都搞好了 但是还不好 配置的主机 制定的目录 还是 ...

  5. mac apache配置虚拟主机

    设置虚拟主机 在终端运行“sudo vi /etc/apache2/httpd.conf”,打开Apche的配置文件 在httpd.conf中找到“#Include /private/etc/apac ...

  6. 集群配置虚拟主机及部署Hadoop集群碰到的问题

    配置集群方案 Ubuntu下的配置apache虚拟主机方案: 对其中的Master节点配置虚拟主机,可以通过Chrome浏览器访问目录. 安装虚拟主机之前,先安装Apache2 sudo apt-ge ...

  7. 使用WampServer环境,如何配置虚拟主机域名

    很多人不会配置虚拟主机,我这里简单交一下大家,分三步: 1.在 C:\Windows\System32\drivers\etc 文件夹中的文件 Hosts 文件修改代码为: 127.0.0.1 loc ...

  8. CentOS 7 配置虚拟主机站点

    1.进入/etc/httpd/conf 下 将httpd.conf 打开. 2.将DocumentRoot注释掉.(将ServerName 打开要不会有错误警告). 3.将虚拟主机站点配置包含进来:I ...

  9. 【转】Apache 配置虚拟主机三种方式

    Apache 配置虚拟主机三种方式  原文博客http://www.cnblogs.com/hi-bazinga/archive/2012/04/23/2466605.html 一.基于IP 1. 假 ...

随机推荐

  1. Android:Gradle sync failed: Another 'refresh project' task is currently running for the project

    android studio 克隆项目后,重新导入后显示Gradle sync failed: Another 'refresh project' task is currently running ...

  2. linux 光盘yum源搭建

    1.挂载光盘 2.进入 /etc/yum.repos.d 目录,修改其它配置文件后缀名 mv CentOS-Base.repo CentOS-Base.repo.bakmv CentOS-CR.rep ...

  3. c# 将秒数转换成时,分,秒的方法

    TimeSpan ts = , ,Convert.ToInt32( duration)); string str = ""; ) { str = ts.Hours.ToString ...

  4. python汉字转拼音

    上代码: #!/usr/bin/env python # -*- coding:utf-8 -*- """ Author:cleverdeng E-mail:clverd ...

  5. 为website安装免费的letsencrypt证书

    Certbot官网:https://certbot.eff.org 1. 安装certbot命令 wget https://dl.eff.org/certbot-auto chmod a+x cert ...

  6. 使用 Azure CLI 管理 Azure 虚拟网络和 Linux 虚拟机

    Azure 虚拟机使用 Azure 网络进行内部和外部网络通信. 本教程将指导读者部署两个虚拟机,并为这些 VM 配置 Azure 网络. 本教程中的示例假设 VM 将要托管包含数据库后端的 Web ...

  7. JavaScript DOM 編程藝術(2版) 綜合實例Band js代碼

    function addLoadEvent(func){ var oldonload=window.onload; if(typeof window.onload!='function') { win ...

  8. mongodb/python3.6/mysql的安装

    1 下载与解压 在官网下载mongodb安装包 tar -zxvf mongodb-linux-x86_64-ubuntu1604-3.4.0.tgz 2 移动安装文件 sudo mv mongodb ...

  9. [翻译] SCRecorder

    SCRecorder https://github.com/rFlex/SCRecorder An easy Vine/Instagram like video and/or audio record ...

  10. spring4声明式事务--01注解方式

    1.在spring配置文件中引入 tx 命名空间 xmlns:tx="http://www.springframework.org/schema/tx" 2.配置事务管理器 < ...