物理机访问虚拟机中搭建的网站的方法以及遇到的问题解决

版权声明: https://blog.csdn.net/Breeze_CAT/article/details/80630050

环境描述:

物理机中没有搭建任何环境,将apache搭建在虚拟机(vmware win7 x64)中,使用wamp,apache+mysql,使用物理机如何访问虚拟机中的php网页。

连通网络

首先我们要使物理机和虚拟机在一个内网中才能成功访问。配置如下:

  1. 将物理机的vmnet8网卡的ipv4地址改为192.168.75.1
    具体步骤:1. 控制面板->网络和共享中心->更改适配器设置->选择vmnet8网卡->属性->Internet协议版本4(TCP/Ipv)
    选择“使用下面的ip地址选项”,配置静态ip为192.168.75.1掩码为C类255.255.255.0
    这里写图片描述
  2. 配置目标虚拟机网络模式为NAT
    这里写图片描述
  3. 配置虚拟机NAT
    具体步骤:在VMware中选择->编辑->虚拟网络编辑器->(右下角)更改设置->选择vmnet8网卡->将下面的子网ip地址和子网掩码改为192.168.75.0 255.255.255.0
    这里写图片描述
    这里写图片描述
    这里写图片描述
  4. 配置DHCP地址池
    具体步骤:(还是在刚才的虚拟网络编辑器中的vmnet8网卡下)点击DHCP设置->配置起始ip段和终止ip段为192.168.75.128-192.168.75.254

    这里写图片描述

  5. 启动虚拟机

Apache配置

  1. 打开Apache中的httpd.conf(在apache\apache2.4.9\conf目录下)。
  2. 找到 <Directory “c:/wamp/www/” > 将倒数第二行的Require all local改为Require all granted
<Directory "c:/wamp/www/">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #

#   onlineoffline tag - don't remove
    Require all local
</Directory>

之后启动服务器,在cmd下输入ipconfig -all查看虚拟机ipv4地址,使用物理机直接访问这个地址就可以了
这里写图片描述这里写图片描述

猜你喜欢

转载自blog.csdn.net/Breeze_CAT/article/details/80630050
今日推荐