Mac 下 MAMP配置虚拟主机

用MAMP PRO的用户请忽略以下

先进入apache的配置文件httpd.conf,路径是/Applications/MAMP/conf/apache/httpd.conf,用文本编辑器打开,command+f查找一下‘vhosts’关键字,来到了这一行

#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

把前面的#号去掉,表示这句话生效,这句话的意思就是使虚拟地址的配置文件生效。

保存后,用文本编辑器打开 /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf,加入需要配置的虚拟地址,大概是这样的:

<VirtualHost *:80>
    DocumentRoot "/Applications/MAMP/htdocs/thinkphp5/public"
    ServerName tests.cn
    ServerAlias tests.cn
    <Directory "/Applications/MAMP/htdocs/thinkphp5/public">
        Options Indexes FollowSymLinks   
        AllowOverride All
        Order deny,allow
        # Allow from all  注意:这句我加上去还是会报无法接入该服务器,所以我用了下面这句
        Require all granted
  
    </Directory>
</VirtualHost>

保存后,来到host配置文件,/etc/hosts,可以进入finder,shift+command+G,输入/etc,回车后找到hosts文件,用编辑器打开,也可以直接在终端输入sudo vi /etc/hosts,然后添加一行解析的语句

127.0.0.1 tests.cn
保存以后,重启一下apache,在浏览器输入tests.cn,就是你刚才设置的虚拟域名,到这就成功了。

以上就是MAMAP中Apache配置

如果用的是Mac 自带的apache
httpd.conf      : /etc/apache2/httpd.conf
httpd-vhosts.conf : /etc/apache2/extra/ /etc/vhosts.conf
hosts 位置不变

注意:/etc/apache2/extra/httpd-vhosts.conf文件有两个配置虚拟主机的案例
开启虚拟主机的话, 需用#注释掉这俩个案例,不然重启apache 会报错

Apache默认安装路径在 /private/etc/apache2/ 
apache 终端命令:
查看版本:sudo apachectl -v
启动:sudo apachectl start
停止:sudo apachectl stop
重启:sudo apachectl restart



  

猜你喜欢

转载自www.cnblogs.com/ztshuai/p/12677637.html