apache php 配置虚拟域名

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>
#网站备注:

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值