apache 多站点设置

apache 多站点设置

1、多IP多端口多站点配置

修改APACHE的配置文件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
ServerName www.example2.org
</VirtualHost>
————————————————————

2、多IP单端口多站点

———————————————————–
<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>
—————————————————————

3、单IP单端口多站点

—————————————————————
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>

备注:在apache配置中注释以"#"开头,切注释行必须是单独一行.否者报错.

原文地址:https://www.cnblogs.com/suizhikuo/p/2761642.html