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

windows apache 配置多个服务站点 .txt

2011-11-01 09:13 507 查看
 
windows apache 配置多个服务站点

通用 2009-07-02 09:36:01 阅读149 评论0   字号:大中小 订阅

虚拟主机配置示例

方法一:多个APACHE服务

更改第一个站点的根目录:

在文件Apache2.2\conf\httpd.conf中查找 DocumentRoot 属性,将后面的路径改为你的主站点的路径,

如:D:\www\web1

为第二个Apache服务建立配置文件:

复制并重命名httpd.conf为web2.conf(举个例子而已,也可以叫my.conf等等),

修改 web2.conf中的

Listen 8080(原来为80)

ServerName localhost:8080(原来为80)

DocumentRoot “D:/www/web2″ (原来为web1)

添加第二个Apache服务:

Apache安装目录的bin子目录下,使用如下命令将Apache安装为Windows NT服务:

httpd.exe -k install -n “服务名” -f “d:\apache2.2\conf\web2.conf”

其他的命令:

将Apache安装为Windows NT服务:

httpd -k install

指定服务的名称,当你在同一机器上安装多个Apache服务时,你必须为它们指定不同的名字。

httpd -k install -n “服务名”

为不同名称的服务使用不同的配置文件,则安装时需要指定配置文件:

httpd -k install -n “服务名” -f “c:\files\my.conf”

如果你使用的是第一个命令,也就是除 -k install 外没有其它命令行参数,那么被安装的服务名称将是:Apache2 ,配置文件将使用conf\httpd.conf 。

移除一个Apache服务:

httpd -k uninstall

使用下述命令移除特定名称的Apache服务:

httpd -k uninstall -n “服务名”

通常,启动、重启、关闭Apache服务的方法是使用Apache Service Monitor工具,另外也可以使用控制台命令:NET START Apache2 和 NET STOP Apache2 或者通过Windows服务控制面板。在启动Apache服务之前,你应当使用下面的命令检查一下配置文件的正确性:

httpd -n “服务名” -t

你可以通过命令行开关来控制Apache服务。要启动一个已经安装的Apache服务,可以使用:

httpd -k start

要停止一个已经安装的Apache服务,可以使用:

httpd -k stop



httpd -k shutdown

要重启一个运行中的Apache服务,强制它重新读取配置文件,可以使用:

httpd -k restart

方法二:配置虚拟主机

    单IP单端口多站点

      修改httpd.conf

-----------------------------------------------------------------------------------------------------------------------------------

Listen 80

NameVirtualHost 192.168.1.15                              #接收请求的IP地址

<VirtualHost 192.168.1.15>                                   #绑定的ip

    ServerAdmin  test@test.com                               #管理员邮箱

    DocumentRoot "D:/Inetpub/www/maidou/"           #网站目录

    ServerName www.test.com                                  #主机名(域名)

    DirectoryIndex  index.php                                      #主目录默认页

    ServerAlias   test.other.com admin.other.com       #做出响应的域名

    ErrorLog logs/error_log.log                                   #错误日志

    CustomLog logs/custom.log common                    #用户日志

    <Directory "D:/Inetpub/www/maidou/">

     Options Indexes FollowSymLinks

     AllowOverride All                                              #AllowOverride指明Apache服务器是否加载.htacess

     Order allow,deny

     Allow from all

   </Directory>

    </VirtualHost>

# 多台可以再添加

<VirtualHost 192.168.1.15>

    DocumentRoot "D:/Inetpub/www/other/"                

    ServerName www.other.com                                    

    <Directory "D:/Inetpub/www/other/">

       Options Indexes FollowSymLinks

       AllowOverride All

       Order allow,deny

       Allow from all

   </Directory>

</VirtualHost>

**************************************************----------------------------------------------------------------------------------

     以上设置的监听端口是80,要保证域名不同。

如果同时有多个虚拟主机,而且经常变动,那就可以在httpd.conf文件的末尾加上一句

---------------------------------------------------------------------------------------------------------------------

include DIR/*.conf                                #DIR为你虚拟主机配置文件的目录

---------------------------------------------------------------------------------------------------------------------

然后,将每一个虚拟主机的配置做一个单独的.conf文件,放在DIR目录下,到时候只要添加删除文件就可以了

        多IP单端口多站点

         修改httpd.conf

-----------------------------------------------------------------------------------------------------------------------------------

<VirtualHost 192.168.1.1:80>

DocumentRoot "/usr/local/apache/a"

ServerName   www.a.com

ServerAlias a.com

DirectoryIndex index.html index.php

</VirtualHost>

NameVirtualHost 192.168.1.2:80

<VirtualHost 192.168.1.2:80>

DocumentRoot "/usr/local/apache/b"

ServerName   www.b.com

ServerAlias b.com

DirectoryIndex index.php

</VirtualHost>

<VirtualHost 192.168.1.2:80>

DocumentRoot "/usr/local/apache/c"

ServerName   www.c.com

ServerAlias c.com

DirectoryIndex index.php

</VirtualHost>

-------------------------------------------------------------------------------------------------------------------------------------

     多IP多端口多站点

    修改httpd.conf

-------------------------------------------------------------------------------------------------------------------------------------

Listen 172.20.30.40:80

Listen 172.20.30.40:8080

Listen 172.20.30.50:80

Listen 172.20.30.50:8080

<VirtualHost 172.20.30.40:80>

DocumentRoot /www/example1-80

ServerName www.example1.com

</VirtualHost>

<VirtualHost 172.20.30.40:8080>

DocumentRoot /www/example1-8080

ServerName www.example1.com

</VirtualHost>

<VirtualHost 172.20.30.50:80>

DocumentRoot /www/example2-80

ServerName www.example1.org

</VirtualHost>

<VirtualHost 172.20.30.50:8080>

DocumentRoot /www/example2-8080

Serv
4000
erName www.example2.org

</VirtualHost>

***********************************************----------------------------------------------------------------------

虚拟目录的设置

----------------------------------------------------------------------------------------------------------------------

Alias /phpmyadmin "E:/www"

<Directory "e:/www">

AllowOverride None

Options Indexes FollowSymLinks Includes

Order allow,deny

Allow from all

</Directory>

*******************************-----------------------------------------------------------------------------------------

添加名为test的虚拟目录,并指向E:\www目录
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息