您的位置:首页 > 运维架构 > Apache

搭建本地环境,本地使用apache设置绑定多个域名

2017-06-16 11:04 507 查看
使用的是phpstudy本地LAMP环境,主要通过修改Apache的vhosts.conf和本地的hosts两个文件来实现

通常使用的是同一端口不同域名访问不同的根目录

首先设置Apache的vhosts.conf

第一个网站使用域名一访问目录D:\software\phpstudy\WWW\laraDemoshop\public

第二个网站使用localhost.cn域名访问目录D:\software\phpstudy\WWW

<VirtualHost *:80>

    DocumentRoot "D:\software\phpstudy\WWW\laraDemoshop\public"

    ServerName 域名一

    ServerAlias 

  <Directory "D:\software\phpstudy\WWW\laraDemoshop\public">

      Options FollowSymLinks ExecCGI

      AllowOverride All

      Order allow,deny

      Allow from all

      Require all granted

  </Directory>

</VirtualHost>

<VirtualHost *:80>

    DocumentRoot "D:\software\phpstudy\WWW"

    ServerName localhost.cn

    ServerAlias 

  <Directory "D:\software\phpstudy\WWW">

      Options FollowSymLinks ExecCGI

      AllowOverride All

      Order allow,deny

      Allow from all

      Require all granted

  </Directory>

</VirtualHost>

注意,修改的Apache的配置文件,修改完成后一定要重启,作者就是因为忘记重启,怎么都不生效,严重到怀疑人生。

然后修改本地的hosts目录,路径一般如下C:\Windows\System32\drivers\etc

修改的时候你应该要有权限,注意都是指向127.0.0.1不要加端口号

# 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.

127.0.0.1 域名一

127.0.0.1 localhost.cn

保存修改,在命令行模式使用

ipconfig/flushdns清理下dns缓存,试一下,应该ok了。

参考文章: http://booby325.iteye.com/blog/1757303 https://jingyan.baidu.com/article/948f59241fa06cd80ef5f969.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: