apache php 配置虚拟域名

版权声明:Yangliwei 版权所有 https://blog.csdn.net/qq_32674347/article/details/87559241

1,在apache的目录中找到httpd-vhosts.conf文件

加入你要添加的域名是:y.cn 地址是:D:\PHPWAMP_IN3\wwwroot\TP5-blog\public

<VirtualHost *:80>
    #绑定主域名
    ServerName y.cn
    #绑定第二域名

    DocumentRoot "D:\PHPWAMP_IN3\wwwroot\TP5-blog\public"
  <Directory "D:\PHPWAMP_IN3\wwwroot\TP5-blog\public">
      Options Indexes FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all
  </Directory>
</VirtualHost>
#网站备注:blog

2,在hosts文件中写入刚才的域名和对应的ip ,直接添加在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
#	::1             localhost

127.0.0.1 y.cn

3,重启apache服务器

4,在浏览器打开y.cn

5,此时会遇到一个问题:localhost打开的也是y.cn的内容,因为localhost和127.0.0.1是一个东西

解决办法:

打开 httpd-vhosts.conf 添加如下代码:documentroot目录指向服务器的根目录

#站点名称:localhost

<VirtualHost *:80>
    #绑定主域名
    ServerName localhost
    #绑定第二域名

    DocumentRoot "D:\PHPWAMP_IN3\wwwroot"
  <Directory "D:\PHPWAMP_IN3\wwwroot">
      Options Indexes FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all
  </Directory>
</VirtualHost>
#网站备注:

猜你喜欢

转载自blog.csdn.net/qq_32674347/article/details/87559241
今日推荐