MAC本apache+php配置虚拟域名时踩的坑

昨天在调试Mac自带的Apache+PHP配置域名时,调试的让我怀疑人生。顿时心里一万个草泥马,我就是配置个虚拟域名啊,这么让我受伤 。

1 首先检查一下Apache是否开启,

qutao@bogon  ~/workspace  apachectl -version
Server version: Apache/2.4.33 (Unix)
Server built:   Apr  3 2018 17:54:07
 qutao@bogon  ~/workspace 

2 再看看PHP是否正常开启

 qutao@bogon  ~/workspace  PHP -v
PHP 7.1.16 (cli) (built: Apr  1 2018 14:10:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
 qutao@bogon  ~/workspace 

发现 Apache+PHP都正常运行 那就OK 

3 配置项目路径,我自己的项目路径是 /Users/qutao/workspace,而Apache默认的项目路径在/Library/WebServer/Documents

修改文件/private/etc/apache2/httpd.conf的项目入口目录

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Users/qutao/workspace"


#同时打开PHP7

LoadModule php7_module libexec/apache2/libphp7.so

  #LoadModule perl_module libexec/apache2/mod_perl.so

 

 4 该配置Apache的虚拟主机名了

/private/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
        DocumentRoot "/Users/qutao/workspace"
        ServerName local_dev.com
#       ErrorLog "/private/var/log/apache2/test-error_log"
#       CustomLog "/private/var/log/apache2/test-access_log" common

        <Directory "/Users/qutao/workspace">
                AllowOverride none
                Require all denied
                Options Indexes FollowSymLinks
                AllowOverride None
                Require all granted
        </Directory>
</VirtualHost>

5 修改一下hosts  目录结构/private/etc/hosts

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
127.0.0.1       local_dev.com

6 配置完重启一下 Apache

 sudo apachectl restart

开始访问自己的主机名local_dev.com

浏览器就开始未找到域名地址,这就纳闷了 怎么还这样了呢

 

然后我就开始看下Apache 的日志啦 , 也没看出啥端倪,看着都没啥毛病,就是访问不通呢

然后我就吧 虚拟主机的访问的日志 及错误日志都打开 再试试看 ,最后还是无果

那我就改个域名试试,抱着试试的态度

127.0.0.1       localdev.com

虚拟主机名字也改为同上,然后在访问一下奇迹了

然后就开始了我的百度问答,为什么local_dev.com, apahce不支持呢, localdev.com 就可用呢?

把百度的别人的原话粘贴过来

其实这里有个RFC 952规范 :

A "name" (Net, Host, Gateway, or Domain name) is a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus sign (-), and period (.)

//规范指出域名只能是字母、数字和短线(-)还有点(.)。

 

不知道是否是这样Apache 就不进行解析了,可以请大家指教

posted on 2019-03-28 13:09  totau  阅读(315)  评论(0编辑  收藏  举报

导航