Mac配置虚拟主机
一、启动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配置虚拟主机的更多相关文章
- mac 配置虚拟主机
http://www.upwqy.com/details/4.html 编辑httpd.conf文件,输入命令: vim /etc/apache2/httpd.conf 编辑httpd-vhosts. ...
- windows和mac下分别配置虚拟主机
windows下配置 1.找到apache的配置文件,httpd.conf 2.找到 LoadModule rewrite_module modules/mod_rewrite.so 去掉前边的# 3 ...
- 转载:mac系统XAMPP配置虚拟主机
安装完xampp后,想添加一个virsualhost,一直报错.查了半天资料,都是乱说,后来看到了一篇国外的文章,终于弄出来了,整理一下. 第一步,配置本地hosts sudo vi /etc/hos ...
- mac 上 mamp 配置虚拟主机 具体过程 ?
https://www.zhihu.com/question/32320396 mac 上 mamp 配置虚拟主机 具体过程 ? 按照哪些配置什么的 都搞好了 但是还不好 配置的主机 制定的目录 还是 ...
- mac apache配置虚拟主机
设置虚拟主机 在终端运行“sudo vi /etc/apache2/httpd.conf”,打开Apche的配置文件 在httpd.conf中找到“#Include /private/etc/apac ...
- 集群配置虚拟主机及部署Hadoop集群碰到的问题
配置集群方案 Ubuntu下的配置apache虚拟主机方案: 对其中的Master节点配置虚拟主机,可以通过Chrome浏览器访问目录. 安装虚拟主机之前,先安装Apache2 sudo apt-ge ...
- 使用WampServer环境,如何配置虚拟主机域名
很多人不会配置虚拟主机,我这里简单交一下大家,分三步: 1.在 C:\Windows\System32\drivers\etc 文件夹中的文件 Hosts 文件修改代码为: 127.0.0.1 loc ...
- CentOS 7 配置虚拟主机站点
1.进入/etc/httpd/conf 下 将httpd.conf 打开. 2.将DocumentRoot注释掉.(将ServerName 打开要不会有错误警告). 3.将虚拟主机站点配置包含进来:I ...
- 【转】Apache 配置虚拟主机三种方式
Apache 配置虚拟主机三种方式 原文博客http://www.cnblogs.com/hi-bazinga/archive/2012/04/23/2466605.html 一.基于IP 1. 假 ...
随机推荐
- this and super
this 和 super 的区别:this, 先从本类找属性和方法,本类找不到再从父类找.super, 从父类找. this 和 super 都可以调用构造方法,所以this() 和 super() ...
- Python 中单双引号
TODO, 在python中, 其实单双引号还是有分别的, 具体是什么?
- CentOS6.4 下安装 MySql5.5.13
1.卸载系统自带的MySql 1.1.查看该操作系统上是否已经安装了mysql数据库 [root@xhTest-1 ~]# rpm -qa | grep mysql 1.2.删除原mysql数据库 1 ...
- .Net Core+Vue.js+ElementUI 实现前后端分离
.Net Core+Vue.js+ElementUI 实现前后端分离 Tags: Vue 架构 前端采用:Vue.js.Element-UI.axios 后端采用:.Net Core Mvc 本项目是 ...
- .net下log4net的使用
这里以控制台应用程序为例 首先是要添加引用: 安装后可以看到项目中多了log4net的引用: 添加应用程序配置文件app.config,配置log4net <?xml version=" ...
- idea常用到的命令
idea大小写转换:ctr+shift+u ctrl+alt+b,跳转到接口的方法实现处
- [翻译] AAPullToRefresh
AAPullToRefresh 效果: Requirement - 需要的环境 ARC. iOS 6 or higher(tested on iOS 6, 7 and 8). Install - 安装 ...
- AVAudioPlayer简易封装
AVAudioPlayer简易封装 [说明] AVAudioPlayer简易封装,仅仅支持播放,暂停,停止,暂停时候带有渐隐效果,自己用,没有参考价值. [源码] https://github.com ...
- Vmware Horizon 服务器替换 ssl 证书
先申请好证书,如通配符SSL证书 *.centaline.com.cn ,公网的证书供应商会给到3个文件:centaline.com.cn.crt .centaline.com.cn.csr.cent ...
- VMware下 CentOS 连接外网问题(笔记)
虚拟机连接外网有三种模式.桥接.Nat.Host-Only.三者的区别,详见 实例讲解虚拟机3种网络模式(桥接.nat.Host-only) 使用虚拟机连接外网时,一定要充分考虑本地的网络环境!!! ...