本地配置虚拟域名(Apache)

PHP luoluolzb 浏览2470次

php开发网站时,默认情况下我们是使用localhost访问我们的设计的网站,那么怎么在本机上配置一个域名,方便我们访问呢。

其实很简单,这里假设要配置的域名为test.com,分三个步骤:
(注意:这里是Apache服务器的配置方法)

修改系统hosts配置文件

文件位置: C:\Windows\System32\drivers\etc\hosts
文件内容:

    # Copyright (c) 1993-2009 Microsoft Corp.
    #
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    #
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    #
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    #
    # For example:
    #
    #      102.54.94.97     rhino.acme.com          # source server
    #       38.25.63.10     x.acme.com              # x client host

    # localhost name resolution is handled within DNS itself.
        127.0.0.1       localhost

我们只需要添加一行:

    127.0.0.1       test.com

修改apache配置文件

文件位置:..\phpStudy\PHPTutorial\Apache\conf\httpd.conf
搜索:

#LoadModule vhost_alias_module modules/mod_vhost_alias.so

去掉前面的注释符号#即可

配置vhost.conf文件

找到:..\phpStudy\PHPTutorial\Apache\conf
增加配置如下:

<VirtualHost _default_:80>
  DocumentRoot "E:\htdocs\test.com"
  ServerName test.com
  <Directory "E:\htdocs\test.com">
    Options -Indexes +FollowSymLinks +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>

其中的E:\htdocs\test.com为网站位置,请自行修改。

本文标签: PHP Apache

版权声明:本文为作者原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://luoluolzb.cn/articles/44/ben-di-pei-zhi-xu-ni-yu-ming-apache
您需要登录后才发布评论。 点此登录
用户评论 (0条)

暂无评论,赶紧发表一下你的看法吧。