Apache的虚拟主机是一种允许在一如既往台机器上计划四个分化站点的web服务器环境的,正是iis一样能够成立多站点了,可是apache须要在编写制定状态操作,不能够像windows
iis直接点击几下就好了,下边作者来给诸位介绍配置情势。

根据用户的访问控制,Apache搭建多个站点方法详解。① 、修改域名访问情势:

暗许景况下,linux上apache使用的
私下认可文书档案目录是:/var/www
暗中认可端口是:80
即使想昭示温馨的3个系统能源目录,能够行使上边包车型客车措施,执行如下命令:
(1)添加监听端口 #cd /etc/apache2
#vim ports.conf
文本添加:
NameVirtualHost *:8000
Listen 8000
(2)配置虚拟目录
#cd /etc/apache2/sites-available
#cp default default-me
#vim default-me
文本内容如下:

httpd配置内容

httpd2.2
配置文件:
    /etc/httpd/conf/httpd.conf
    /etc/httpd/conf.d/*.conf
服务脚本:
    /etc/rc.d/init.d/httpd
脚本配置文件:
    /etc/sysconfig/httpd
主程序文件:
    /usr/sbin/httpd
    /usr/sbin/httpd.event
    /usr/sbin/httpd.worker
日志文件:
    /var/log/httpd:access_log:访问日志,error_log:错误日志
站点文档:
    /var/www/html
模块文件路径:
    /usr/lib64/httpd/modules    
服务控制和启动:
    chkconfig  httpd  on|off
    service {start|stop|restart|status|configtest|reload} httpd
httpd2.4
配置文件:
    /etc/httpd/conf/httpd.conf
    /etc/httpd/conf.d/*.conf
模块相关的配置文件:
    /etc/httpd/conf.modules.d/*.conf
systemd unit file:
    /usr/lib/systemd/system/httpd.service
主程序文件:
    /usr/sbin/httpd(httpd-2.4支持MPM的动态切换)
日志文件:
    /var/log/httpd: access_log:访问日志,    error_log:错误日志
站点文档:
    /var/www/html
模块文件路径:
    /usr/lib64/httpd/modules    
服务控制:
    systemctl enable|disable httpd.service
    systemctl {start|stop|restart|status} httpd.service

最平时的光景有3种方式。

运行:C:\WINDOWS\system32\drivers\etc

复制代码 代码如下:

httpd的底蕴配置

1)修改监听的ip和port,在主配置文件/etc/httpd/conf/httpd.conf中期维修改,格式如:Listen 
[IP:]POTiguanT。供给留意的有3点:

  ①省略IP表示匹配本机全部ip;
  ②Listen指令可重新出现多次;
  ③修改监听socket,重启服务进程方可生效。

  示例:

[root@happiness ~]# vim /etc/httpd/conf/httpd.conf
    Listen 80
    Listen 192.168.4.50:8090
[root@happiness ~]# systemctl start httpd.service
[root@happiness ~]# ss -tan
State       Recv-Q Send-Q             Local Address:Port                            Peer Address:Port              
LISTEN      0      128                 192.168.4.50:8080                                       *:*                  
LISTEN      0      5                  192.168.122.1:53                                         *:*                  
LISTEN      0      128                            *:22                                         *:*                  
LISTEN      0      128                    127.0.0.1:631                                        *:*                  
LISTEN      0      100                    127.0.0.1:25                                         *:*                  
ESTAB       0      52                 192.168.4.119:22                              192.168.4.93:49948              
LISTEN      0      128                           :::80                                        :::*                  
LISTEN      0      128                           :::22                                        :::*                  
LISTEN      0      128                          ::1:631                                       :::*                  
LISTEN      0      100                          ::1:25                                        :::* 

2)长连接。tcp三番五次建立后,各类财富拿到成功后不全断开连接,而是继续等待别的财富请求的实行。对并发访问量较大的服务器,长连接机制会使得后续有些请求不能拿到符合规律响应,对那种景况,大家得以选择较短的持久连接时间长度,以及较少的伸手数量。

  配置指令:

    KeepAlive On|Off        #是还是不是启用长连接
    KeepAliveTimeout Seconds     #逾期时间长度
    MaxKeepAliveRequests Number       #最多维持稍稍个长连接的呼吁

  示例:

[root@happiness ~]# vim /etc/httpd/conf.d/keepalive.conf  #新建
    KeepAlive On
    KeepAliveTimeout 30
    MaxKeepAliveRequests 200
[root@happiness ~]# systemctl restart httpd.service
[root@happiness ~]# telnet 192.168.4.50 8080
Trying 192.168.4.50...
Connected to 192.168.4.50.
Escape character is '^]'.
GET /index.html HTTP/1.1     
HOST:192.168.4.50    #输入后连按两次Enter

HTTP/1.1 200 OK
Date: Fri, 08 Jun 2018 04:25:03 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Fri, 08 Jun 2018 01:50:41 GMT
ETag: "17-56e17a0a33249"
Accept-Ranges: bytes
Content-Length: 23
Content-Type: text/html; charset=UTF-8

<h2>hello, world.</h2>
#注意:此处因为启用了KeepAlive,连接没有断开,可以继续输入内容;如果没有启用KeepAlive则请求成功后会直接退出telnet

3)自定义web站点。在httpd服务的主配置文件中,暗中认可情状下DocumentRoot
“/var/www/html”定义了暗许web站点目录的门路。如需自定义站点,需按如下格式举办添加:

  httpd-2.2:

    DocumentRoot   “/PATH/TO/FILE”
    <Directory “/PATH/TO/FILE”>              
      Options Indexes FollowSymLinks
      AllowOverride None 
 #用于定义每一个目录下.htaccess文件中的指令类型,但一般设置None
      Order
allow,deny #概念默许的走访权限与Allow和Deny语句的处理顺序,此处先匹配allow再匹配deny
      Allow from all 
#本着客户机的域名或IP地址进行走访限制,如:Allow from all或许Deny from
192.168等
    </Directory>

  httpd-2.4:

    DocumentRoot   “/PATH/TO/FILE”
    <Directory “/PATH/TO/FILE”>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all
granted  #http-2.4中的允许全数人访问,若是要禁止某些IP或域名的造访,如:Require
not ip 1.1.1.一 、Require not host xxxx.com可能禁止全体人访问Require all
denied
     </Directory>

当中options包蕴以下的可选参数:

参数 说明
Indexes 允许目录浏览,当客户仅指定要访问的目录,但没有指定要访问的文件,且目录下不存在默认文档时,显示该目录中的文件及子目录列表索引
MultiViews 允许内容协商的多重视图,允许返回指定的访问目录下的相关联的文件
All All包含了除MultiViews之外的所有特性,如没有指定options,默认为All
ExecCGI 允许在该目录下执行CGI脚本
FollowSymLinks 允许跟踪符号链接到源文件
Includes 允许服务器端包含功能
IncludesNoExec 允许服务器端包含功能,但禁止执行CGI脚本
None 不调用options参数

 

 

 

 

 

 

 

 

 

  示例:

[root@happiness ~]# mkdir -p /test/html
[root@happiness ~]# vim /test/html/test.html
   <h2>test web站点</h2>
[root@happiness ~]# chcon -R --reference /var/www/html /test/html #复制/var/www/html的selinux安全上下文到/data/html,如果没复制安全上下文可能会导致访问index.html出现403的提示
[root@happiness ~]# vim /etc/httpd/conf/httpd.conf
   #DocumentRoot "/var/www/html"  #注释默认的web根站点
   DocumentRoot "/test/html"  #定义要启用的web根站点
   <Directory "/test/html">
        Options None
        AllowOverride None
        Require all granted
   </Directory>
[root@happiness ~]# systemctl restart httpd.service
结果:

澳门金沙国际 1

率先种:单IP不一样端口

打开:hosts文件

<VirtualHost *:8000 >
    ServerAdmin webmaster@localhost
    DocumentRoot /wwwroot
    <Directory / >
Options FollowSymLinks
AllowOverride None
    </Directory>
    <Directory /wwwroot/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
    </Directory>
    ErrorLog /var/log/apache2/error.log
    # Possible values include: debug, info, notice, warn, error,
crit,
    # alert, emerg.
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
</VirtualHost>

httpd的访问控制

1)在Directory中基于IP地址达成访问控制

  http-2.第22中学基于IP地址的访问控制是利用Allow和Deny来贯彻的,如:
      <Directory  “/PATH/TO/FILE”>
          Options Indexes FollowSymLinks
          AllowOverride None
          Order allow, deny
          Allow  from  IP | NetAddr
          Deny  from  IP | NetAddr
      </Directory>
  在那之中NetAddr的格式可类似:172.1六 、172.16.0.0、172.16.0.0/1陆 、172.16.0.0/255.255.0.0。

  httpd-2.4中基于Ip地址访问的操纵是选用Require达成,如:
      <Directory  “/PATH/TO/FILE”>
         AllowOverride none
         Options none
         <RequireAll>
            Require ip IP | NetAddr #允许访问的IP或网段
            Require not ip IP | NetAddr
#拒绝访问的Ip或网段
         </RequireAll>
      </Directory>
  其它httpd-2.4版本中还足以选拔host名来开始展览访问控制,如:
      <Directory  “/PATH/TO/FILE”>
         AllowOverride none
         Options none
         <RequireAll>
           Require host
google.com  #允许来自域名为google.com全部主机的访问
           Require not host
www.xxxx.com  #不允许来自主机名为www.xxxx.com的造访
         </RequireAll>
      </Directory>

  示例:

[root@happiness ~]# mkdir /test/virtualhtml
[root@happiness ~]# vim /test/virtualhtml/virtualtest.html
     <h2>test for virtual</h2>
[root@happiness ~]# vim /etc/httpd/conf.d/virualhost.conf
  <VirtualHost 192.168.4.50:8080>
      DocumentRoot "/test/virtualhtml"
      <Directory "/test/virtualhtml">
          AllowOverride None
          Options None
          <RequireAll>
              Require all granted
              Require not ip 192.168.4.154    #禁止ip192.168.4.154的主机访问
          </RequireAll>
      </Directory>
  </VirtualHost>
结果:

澳门金沙国际 2  澳门金沙国际 3

 2)在Directory中基于用户的访问控制

  在Directory中辅助的认证格局有三种 basic明文认证和
digest消息摘要认证,不是怀有浏览器都协理摘要认证,由此一般的话用的较多的是
basic明文认证。
  用htpasswd命令生成认证的安插文件:

[root@happiness ~]# htpasswd -cb /data/httpduser walter 123456
[root@happiness ~]# htpasswd -b /data/httpduser alex 123456
[root@happiness ~]# cat /data/httpduser 
  walter:$apr1$CYZpqBy5$gxnNCiKSIX.qN8LRI809L.
  alex:$apr1$vGncT2dc$.S0TsnDFINqf5BhHP0Hvi.
[root@happiness ~]# chcon -R --reference /var/www /data/httpduser

  编辑主配置文件:

[root@happiness ~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/test/html"
<Directory "/test/html">
    Options None
    AllowOverride None
    AuthType Basic  #认证方式Basic
    AuthName "user test"    #授权机制名称
    AuthUserFile "/data/httpduser"  #授权文件位置
    Require user alex  #允许访问的用户
</Directory>
[root@happiness ~]# systemctl restart httpd.service
结果:

澳门金沙国际 4  澳门金沙国际 5  澳门金沙国际 6

 3)基于组的用户访问控制

  除了对用户做访问控制之外,还能够将用户划分为对应的组从而依照组来做相应的访问控制,接着上二个例子中的用户来做组访问控制。
  创立组文件:

[root@happiness ~]# vim /data/httpdgroup
   groupA:walter
   groupB:alex
[root@happiness ~]# chcon -R --reference /var/www /data/httpdgroup

  编辑主配置文件:

[root@happiness ~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/test/html"
<Directory "/test/html">
    Options None
    AllowOverride None
    AuthType Basic  #认证方式Basic
    AuthName "user test"    #授权机制名称
    AuthUserFile "/data/httpduser"  #授权用户文件位置
    AuthGroupFile "/data/httpdgroup"  #授权用户组文件位置
    Require group groupA  #允许访问的组
</Directory>
[root@happiness ~]# systemctl restart httpd.service
结果:

澳门金沙国际 7  澳门金沙国际 8

第三种:多IP同端口(独立IP的杜撰空间)

添加域名指向。

粗体部分是关键点。
(3)发表站点
# ln -s /etc/apache2/sites-available/default-me
/etc/apache2/sites-enabled/001-default
(4)重启服务 #/etc/init.d/apache2 restart
(5)测试
即使能够不奇怪访问就阐明配置不错了。

 httpd的虚拟主机VirtualHost

  平时在一台服务器安装Apache后,大家不得不访问3个web站点,若是我们须要在一台服务器访问多少个web站点,则需求经过Apache的VirtualHost虚拟主机完结,其实便是通过VirtualHost实现访问同三个服务器上的两样目录。
  虚拟主机辅助三种建立章程:

  • 依照ip的点子,要求为各个虚拟主机准备至少二个ip地址,配置格式如:

      <VirtualHost IP:PORT>
        ServerName  “www.xxx.cn”  #虚拟主机域名
        DocumentRoot  “/www/xxx”  #虚拟主机web目录
      </VirtualHost>

    示例:

#创建目录
  [root@happiness ~]# mkdir -p /data/Vip/test1
  [root@happiness ~]# mkdir -p /data/Vip/test2
  [root@happiness ~]# chcon -R --reference /var/www/html /data/Vip #复制安全上下文
#创建index.html文件
  [root@happiness ~]# vim /data/Vip/test1/index.html
      <h1>virtual test based on ip. one</h1>
  [root@happiness ~]# vim /data/Vip/test2/index.html
      <h1>virtual test based on ip. two</h1>
#注释/var/www/html作为根路径
  [root@happiness ~]# vim /etc/httpd/conf/httpd.conf
      #DocumentRoot /var/www/html
#添加virtualhost.conf配置文件(文件名自定义)
  [root@happiness ~]# vim /etc/httpd/conf.d/virtualhost.conf
    <VirtualHost 192.168.4.119:80>
         DocumentRoot "/data/Vip/test1"
         <Directory "/data/Vip/test1">
             AllowOverride None
             Options None
             Require all granted
         </Directory>
    </VirtualHost>

    <VirtualHost 192.168.4.120:80>
        DocumentRoot "/data/Vip/test2"
        <Directory "/data/Vip/test2">
           AllowOverride None
           Options None
           Require all granted
         </Directory>
    </VirtualHost>
#启动httpd服务
  [root@happiness ~]# systemctl start httpd.service
#清空防火墙规则
  [root@happiness ~]# iptables -F
访问结果:
  • 据悉port的格局,必要为各种虚拟主机配置二个单独的port,配置格式如:

      Listen 8080  #钦命别的端口时,必要添加监听该端口
      <VirtualHost IP:PORT>
        ServerName  “www.xxx.cn”  #虚拟主机域名
        DocumentRoot  “/www/xxx”  #虚拟主机web目录
      </VirtualHost>

    示例:

#在上面的基础上直接修改virtualhost文件
[root@happiness ~]# vim /etc/httpd/conf.d/virtualhost.conf
Listen 8080
<VirtualHost 192.168.4.119:80>
    DocumentRoot "/data/Vip/test1"
    <Directory "/data/Vip/test1">
        AllowOverride None
        Options None
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost 192.168.4.119:8080>
    DocumentRoot "/data/Vip/test2"
    <Directory "/data/Vip/test2">
        AllowOverride None
        Options None
        Require all granted
    </Directory>
</VirtualHost>
访问结果:
  • 根据FQDN的艺术,必要为各类虚拟主机配置1个FQDN,配置格式如:

      NameVirtualHost
172.16.100.6:80  #httpd-2.2供给在安插文件中添加此句
      <VirtualHost 172.16.100.6:80>
        ServerName www.xxx.com #指定FQDN
        DocumentRoot “/www/xxxcom”
      </VirtualHost>
      <VirtualHost 172.16.100.6:80>
        ServerName www.xxx.cn #指定FQDN
        DocumentRoot “/www/xxxcn”
      </VirtualHost>

    示例:

#在上面的基础上直接修改virtualhost文件
[root@happiness ~]# vim /etc/httpd/conf.d/virtualhost.conf
<VirtualHost 192.168.4.119:80>
    ServerName www.test1.cn
    DocumentRoot "/data/Vip/test1"
    <Directory "/data/Vip/test1">
        AllowOverride None
        Options None
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost 192.168.4.119:80>
    ServerName www.test2.cn
    DocumentRoot "/data/Vip/test2"
    <Directory "/data/Vip/test2">
        AllowOverride None
        Options None
        Require all granted
    </Directory>
</VirtualHost>
访问结果:
    

其两种:域名绑定根目录的法门(共享IP的虚构空间)

2、修改httpd.conf.

复制代码 代码如下:

Apache的基本配置文件名是”httpd.conf”,其所存放的门道在Apache目录下的conf文件夹下。修改它只必要采纳记事本(提议采纳此外编辑器,带行数的这种,方便修改),生效的话只须要保留httpd.conf,重启apache即可。

配备生效前提,必须修改跟目录为:

~~~~~~~~~~~
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most
configurations
# use only name-based virtual hosts so the server doesn’t need to worry
about
# IP addresses. This is indicated by the asterisks in the directives
below.
#
# Please see the documentation at
# <URL: >
# for further details before you try to setup virtual hosts.
#
# You may use the command line option ‘-S’ to verify your virtual
host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:81
NameVirtualHost *:82
NameVirtualHost *:83
NameVirtualHost *:84
NameVirtualHost *:85
NameVirtualHost *:86
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:81>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-nongye
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-nongye/errornongye.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:82>
<Directory “D:/AppServ/www-chinaec” >
Options FollowSymLinks
#Deny from all
Allow from all
</Directory>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www-chinaec
ServerName www.dede.com
DirectoryIndex index.php index.html
ErrorLog D:/AppServ/www-chinaec/errornongjiale.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:83>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-05110
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-05110/errornong05110.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:84>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/wordpress
ServerName www.dede.com
ErrorLog D:/AppServ/www/wordpress/errornongwordpress.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:85>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/magento
ServerName www.dede.com
ErrorLog D:/AppServ/www/magento/errormagento.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:86>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/magento1322
ServerName www.dede.com
ErrorLog D:/AppServ/www/magento1322/errormagento1322.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:88>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-nongjiale
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-nongjiale/errornongjiale.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.x
DocumentRoot “C:/Apache2.2/docs/dummy-host2.x”
ServerName dummy-host2.x
ErrorLog “logs/dummy-host2.x-error.log”
CustomLog “logs/dummy-host2.x-access.log” common
</VirtualHost>

上面多站点援救的话,修改httpd.conf的第387~264行(差异的httpd.conf大概有异样),也正是在ServerAdmin和ServerName那里,大部分是注释。上面是最首要修改的地点。

<Directory />
Options FollowSymLinks
AllowOverride None
### Order deny,allow
### Deny from all
Order allow,deny
Allow from all
Satisfy all
</Directory>

壹 、单域名单端口设置 如:www.abc.com 默认用80访问

注意:要是是服务器请备份httpd.conf后再修改文件。

不然会油然则生无权访问难点。

尤其表达,apache的安排暗许都在安装目录下的conf目录里面
或者是/etc/apache2
但是早晚要留心,listen.conf文件中端口监听是还是不是开启
正如图,表示已经打开80端口监听

 代码如下

叁 、虚拟主机的配置
(1)基于IP地址的虚拟主机配置
Listen 80
<VirtualHost
172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
<VirtualHost
172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>

一贯暗中认可
① 、单域名单端口设置
如:www.abc.com 默认用80访问

复制代码

(2) 基于IP和多端口的虚拟主机配置
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080

专门表达,apache的计划暗许都在安装目录下的conf目录里面
或者是/etc/apache2
但是早晚要专注,listen.conf文件中端口监听是或不是打开
正如图,表示早已打开80端口监听
一向暗许修改default-server.conf

# ‘Main’ server configuration
#
# The directives in this section set up the values used by the ‘main’
# server, which responds to any
requests that aren’t handled
by a
# <VirtualHost> definition.  These values also provide defaults
for
# any <VirtualHost> containers you may define later in the
file.
#
# All of these directives may appear inside <VirtualHost>
containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

<VirtualHost
172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>

那一个布局最好容易 设置好了,之后,暗许已经能够使用了,只是要把它修改成你要求的域名及走访路径罢了。

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages,
such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin admin@example.com

<VirtualHost
172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>

给一个标准配置吧

#
# ServerName gives the name and port that the server uses to identify
itself.
# This can often be determined automatically, but we recommend you
specify
# it explicitly to prevent problems during startup.
#
# If your host doesn’t have a registered DNS name, enter its IP address
here.
#
ServerName www.example.com:80

<VirtualHost
172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>

复制代码 代码如下:

#
# Deny access to the entirety of your server’s filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
    AllowOverride All
    Require all denied
</Directory>

<VirtualHost
172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>

DocumentRoot “/srv/www/htdocs”
#
# Configure the DocumentRoot
#
<Directory “/srv/www/htdocs”>
# 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
#
# for more information.
Options None
# AllowOverride controls what directives may be placed in .htaccess
files.
# It can be “All”, “None”, or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
AllowOverride None
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled – so if something’s not working
as
# you might expect, make sure that you have specifically enabled it
# below.
#

(3)单个IP地址的服务器上依照域名的虚拟主机配置:
# Ensure that Apache listens on port 80
Listen 80

② 、单域名多端口设置

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory,
but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot “g:/www”
<Directory “g:/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
    #
    # for more information.
    #
    Options Indexes FollowSymLinks

# Listen for virtual host requests on all IP
addresses
NameVirtualHost *:80

复制代码 代码如下:

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

<VirtualHost
*:80>
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>

<Directory “/srv/www/htdocs/bbs”>
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory “/srv/www/htdocs/”>
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
NameVirtualHost   *:80
NameVirtualHost   *:81
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   “www.abc.com “
  DocumentRoot   “/srv/www/htdocs/” 
  </VirtualHost>
<VirtualHost *:81>
  DirectoryIndex   index.php
    ServerName   “www.abc.com:81 “
  DocumentRoot   “/srv/www/htdocs/bbs/” 
  </VirtualHost>

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

<VirtualHost
*:80>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
</VirtualHost>

三 、多域名多端口设置

首先种一般是测试环境,毕竟加了端口,怎么样绑定域名,访问的时候域名后边也需加端口。

(4)在多少个IP地址的服务器上陈设基于域名的虚拟主机:
Listen 80

复制代码 代码如下:

事例分别通过80和8080访问分裂的根目录。

# This is the “main” server running on 172.20.30.40
ServerName server.domain.com
DocumentRoot /www/mainserver

<Directory “/srv/www/htdocs/btc”>
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory “/srv/www/htdocs/bbs”>
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory “/srv/www/htdocs/”>
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
NameVirtualHost   *:80
NameVirtualHost   *:81
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   “www.abc.com “
  DocumentRoot   “/srv/www/htdocs/” 
  </VirtualHost>
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   “www.btc.com “
  DocumentRoot   “/srv/www/htdocs/btc” 
  </VirtualHost>
<VirtualHost *:81>
  DirectoryIndex   index.php
    ServerName   “www.abc.com:81 “
  DocumentRoot   “/srv/www/htdocs/bbs/” 
  </VirtualHost>

差不离在50几行有个Listen 80,在底下添加8080端口。

# This is the other address
NameVirtualHost
172.20.30.50

亟需注意的标题是,多端口监听,一定要小心listen.conf文件,是还是不是打开了相应端口。

 代码如下

<VirtualHost
172.20.30.50>
DocumentRoot /www/example1
ServerName www.example1.com
# Other directives here …
</VirtualHost>
IXDBA.NET社区论坛

您可能感兴趣的稿子:

  • Linux下查看端口占用进程号,程序名的主意
  • 澳门金沙国际 ,Linux/window下何以查看有些端口被哪些程序/进程占用
  • Windwos下使用winscp和批处理达成通过SSH端口上传文件到Linux服务器上
  • Linux利用nc命令监察和控制服务器端口的办法
  • Linux下用netstat查看互联网状态、端口状态
  • 什么样解决windows系统和linux系统中端口被占据的难点
  • linux下mysql开启远程访问权限
    防火墙开放3306端口
  • 行使iptables来布局linux禁止全数端口登陆和绽放钦定端口的点子
  • linux下防火墙开启有个别端口号及防火墙常用命令使用(详解)
  • 详解Linux
    查看服务器开放的端口号

复制代码

<VirtualHost
172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here …
</VirtualHost>

Listen 80
Listen 8080<VirtualHost *:80>
    ServerAdmin admin@myxzy.com
    ServerName localhost:80
    DocumentRoot “g:/www1”
     <Directory “g:/www1”>
     Options  Indexes FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>  
</VirtualHost>
<VirtualHost *:8080>
    ServerAdmin admin@myxzy.com
    ServerName localhost:8080 
    DocumentRoot “g:/www2”
   <Directory “g:/www2”>
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>      
</VirtualHost>

(5)在分歧的端口上运营分化的站点(基于多端口的服务器上布署基于域名的虚拟主机):
Listen 80
Listen 8080

第2种多IP同端口。

NameVirtualHost
172.20.30.40:80
NameVirtualHost
172.20.30.40:8080

IP地址1:192.168.2.2

<VirtualHost
172.20.30.40:80>
ServerName www.example1.com
DocumentRoot /www/domain-80
</VirtualHost>

IP地址2:192.168.1.68

<VirtualHost
172.20.30.40:8080>
ServerName www.example1.com
DocumentRoot /www/domain-8080
</VirtualHost>

端口同是80端口。

<VirtualHost
172.20.30.40:80>
ServerName www.example2.org
DocumentRoot /www/otherdomain-80
</VirtualHost>

 代码如下

<VirtualHost
172.20.30.40:8080>
ServerName www.example2.org
DocumentRoot /www/otherdomain-8080
</VirtualHost>

复制代码

(6)基于域名和基于IP的混合虚拟主机的计划:
Listen 80

<VirtualHost 192.168.1.68:80>
    ServerAdmin admin@myxzy.com
    ServerName localhost:80
    DocumentRoot “g:/www1”
     <Directory “g:/www1”>
     Options FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>  
</VirtualHost>
<VirtualHost 192.168.2.2:80>
    ServerAdmin admin@myxzy.com
    ServerName localhost:80
    DocumentRoot “g:/www2”
   <Directory “g:/www2”>
     Options FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>      
</VirtualHost>

NameVirtualHost
172.20.30.40

其两种同IP不一致域名和根目录(域名的话修改本地host演示)。

<VirtualHost
172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>

 代码如下

<VirtualHost
172.20.30.40>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>

复制代码

<VirtualHost
172.20.30.40>
DocumentRoot /www/example3
ServerName www.example3.net
</VirtualHost>

<VirtualHost 192.168.2.2:80>
    ServerAdmin admin@myxzy.com
    ServerName www.111cn.net
    DocumentRoot “g:/www1”
     <Directory “g:/www1”>
     Options FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>  
</VirtualHost>
<VirtualHost 192.168.2.2:80>
    ServerAdmin admin@myxzy.com
    ServerName www.111cn.net
    DocumentRoot “g:/www2”
   <Directory “g:/www2”>
     Options FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>      
</VirtualHost>

==========================================================================

回顾的说,打开httpd.conf 在最终进入如下内容:

<VirtualHost
127.0.0.2:80>
    DocumentRoot d:/AppServ/www2
    ServerName 127.0.0.2:80
</VirtualHost>

<Directory “d:/AppServ/www2”>
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

“d:/AppServ/www2”
为你的站点存放目录:重启apache2以往,你的虚拟主机就安顿好了,现在就足以由此127.0.0.2,和127.0.0.3跻身差异的站点了。

下面为详细表明分析:

在大家设置APACHE的时候一般暗中认可的apache的布局是惟有三个网站,那样切换起来很不方便人民群众。其实这么些题材很好消除,正是把本机的apache配置成为虚拟服务器。可是,网上海南大学学部分课程的是教用
apache如何配置基于域名的虚拟主机的,而在本机调节和测试网站的时候,一般都是用当地ip(127.0.0.1
或 localhost)直接访问,没有用到域名。所以得把apache配置成为基于ip地址的虚拟主机。

第壹,大家都晓得,全部以127遥遥抢先的ip地址都应该本着本机,并不唯有127.0.0.1,这一点大家能够试试。
那样一来,也便是说本机有丰富多的ip地址供您来开设虚拟主机了。

废话少说,进入正规的布局工作,上边是apache的httpd.conf里有关安插部分(
httpd.conf 位于 Apache2.2\conf ):
壹 、Listen部分,必须一贯钦定端口,不点名ip地址,配置应写为:
Listen 80
二 、不用像基于域名的虚拟主机那样写“NameVirtualHost”。

三 、虚拟主机配置段:在httpd.conf 最终加上
<VirtualHost
127.0.0.2:80>
    DocumentRoot d:/AppServ/www2
    ServerName 127.0.0.2:80
</VirtualHost>

<VirtualHost
127.0.0.3:80>
    DocumentRoot d:/AppServ/www3
    ServerName 127.0.0.3:80
</VirtualHost>…

四 、然后相应的配置好各类目录属性,上面是一个目录属性的头名配置:
<Directory “d:/AppServ/www2”>
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

<Directory “d:/AppServ/www3”>
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

重启apache2未来,你的虚拟主机就布局好了,现在就能够通过127.0.0.1和127.0.0.2,127.0.0.3进来不一样的站点了。

相关文章