cxs7225032 发表于 2018-11-17 09:49:40

apache 虚拟目录 不同主机名 不同端口

  实验环境:rhel6作服务端,宿主机或另开一台win系统作访问端
  实验目的:实现网页多路访问
  实验需求:服务端ip地址:192.168.100.10   访问端ip地址:192.168.100.25(只要是100段的就行)
  1 .首先安装httpd服务,进入配置文件进行配置
  vim /etc/httpd/conf/httpd.conf
  Listen 192.168.100.10:80      //监听端口
  #Listen 80            //ipv6注销掉
  ServerName www.benet.com:80   //主机名


  2 .service httpd start      //开启服务
  service iptables stop    //
  setenforce 0         //关闭防火墙

  此时就可以访问apache了浏览器输入192.168.100.10 可以看到首页

  3 .自定义网页内容,并且重启服务

  4 .再次访问apache,可以看到自定义的内容

  5 . 此时我们来添加虚拟用户
  先进入到配置所在目录 cd /etc/httpd/conf.d
  vim vdir.conf   //创建一个配置文件
  Alias /test "/opt/test/"   //定义一个名字,物理存放在opt
     //定义物理路径
  Options Indexes MultiViews FollowSymLinks   //建立一个索引
  AllowOverride None      //前两行为默认固定格式,不允许重写
  AuthName "hello"      //标志性信息
  authtype basic      //认证类型,基本认证
  authuserfile /etc/httpd/user    //身份验证账户文件
  authgroupfile /etc/httpd/group      //认证组
  require Valid-user          //开启用户认证
  require user test         //仅允许用户登录
  Require group admin      //仅允许组登录
  

  6 .mkdir /opt/test   //在opt创建一个文件,要与上面相同
  echo "this is vdir test" > /opt/test/index.html          //定义一个网页文件

  7 . htpasswd -c /etc/httpd/user li//创建一个li用户
  service httpd restart      //重启服务

  8 . 浏览器输入192.168.100.10/test    进入测试
  这时就需要输入用户及密码才能进入网页

  9 . 下面设置不同主机名访问
  vim host.conf
  NameVirtualHost 192.168.100.10:80    //指定一个ip地址与相对应端口
  //
  ServerAdmin webmaster@dummy-host.example.com    //建立一个管理员邮箱
  DocumentRoot /opt/benet/    //定义站点目录
  ServerName www.benet.com    //服务器名称
  ErrorLog logs/benet.com-error_log   //两个日志,错误日志
  CustomLog logs/benet.com-access_log common//访问日志
  
  
  ServerAdmin webmaster@dummy-host.example.com
  DocumentRoot /opt/accp/
  ServerName www.accp.com
  ErrorLog logs/accp.com-error_log
  CustomLog logs/accp.com-access_log common
                 //定义另一个网页

  10 .mkdir /opt/benet    //创建文件
  mkdir /opt/accp //
  echo "this is benet" > /opt/benet/index.html   //定义网页
  echo "this is accp" > /opt/accp/index.html   //

  11 .rpm -ivh /mnt/Packages/bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm       //DNS解析

  12 .vim /etc/named.conf
  listen-on port 53 { 192.168.100.10; };      //监听端口
  ....
  allow-query   { any; };            //允许所有访问

  13 . vim /etc/named.rfc1912.zones
  zone "benet.com" IN {             //解析benet.com
  type master;
  file "benet.com.zone";      //工作文件为benet.com.zone
  allow-update { none; };
  };
  

zone "accp.com" IN {    //  type master;
  file "accp.com.zone";   //
  allow-update { none; };
  
};
  


  14 .cd /var/named/
  cp -p named.localhost benet.com.zone
  vim benet.com.zone
  @       IN SOA@ admin.benet.com. (             //管理员主机名
  0       ; serial
  1D      ; refresh
  1H      ; retry
  1W      ; expire
  3H )    ; minimum
  NS      @
  A       192.168.100.10
  www INA    192.168.100.10                   //解析网址
  同样设置accp

  15 .service named start
  service httpd restart         //开启服务
  浏览器测试 www.benet.com      www.accp.com


  16 . 下面再进行不同端口测试
  vim /etc/httpd/conf.d/host.conf
  在最底部添加
  NameVirtualHost 192.168.100.10:8080
  
  ServerAdmin webmaster@dummy-host.example.com
  DocumentRoot /opt/benet01/
  ServerName www.benet.com
  ErrorLog logs/benet.com-error_log
  CustomLog logs/benet.com-access_log common
  

  17 .cd /etc/httpd/conf.d/
  mkdir /opt/benet01
  echo "this is benet8080" > /opt/benet01/index.html      //定义网页内容
  18 . vim /etc/httpd/conf/httpd.conf
  Listen 192.168.100.10:80
  Listen 192.168.100.10:8080      //监听8080端口
  #Listen 80

  18 . service httpd restart         //重启服务
  浏览器输入192.168.100.10:8080

  测试完成


页: [1]
查看完整版本: apache 虚拟目录 不同主机名 不同端口