apache单ip多域名多目录配置

自己的vps上放了别人的网站,那怎么样让自己的网站和别人的网站能同时被访问呢?需要使用apache的虚拟主机配置。

配置httpd.conf文件

比如原来是这种只是指向一个目录的配置

DocumentRoot "/opt/lampp/htdocs/ppe112"
<Directory "/opt/lampp/htdocs/ppe112">
#
# 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/trunk/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
# XAMPP
Options Indexes FollowSymLinks ExecCGI Includes #
# 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
# since XAMPP 1.4:
AllowOverride All #
# Controls who can get stuff from this server.
#
Require all granted
</Directory>

把这段话变成

<VirtualHost 198.199..XXX>       #这里填主机的ip地址
ServerName www.AAA.com
DocumentRoot "/opt/lampp/htdocs/AAA"
<Directory "/opt/lampp/htdocs/AAA">
#
# 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/trunk/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
# XAMPP
Options Indexes FollowSymLinks ExecCGI Includes #
# 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
# since XAMPP 1.4:
AllowOverride All #
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
</VirtualHost> <VirtualHost 198.199..XXX> #这里填主机的ip地址
ServerName www.BBB.com
DocumentRoot "/opt/lampp/htdocs/BBB"
<Directory "/opt/lampp/htdocs/BBB">
#
# 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/trunk/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
# XAMPP
Options Indexes FollowSymLinks ExecCGI Includes #
# 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
# since XAMPP 1.4:
AllowOverride All #
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
</VirtualHost>

这样就实现了AAA网站和BBB网站同时在服务器上共存,外部两个域名指向同一个ip,内部解析到不同服务器目录的操作。

PS:这里这里只能正常访问www.AAA.com  www.BBB.com这两个,如果要直接访问AAA.com  BBB.com 也需要如上再配置一遍。

上一篇:Flex相关案例及资源搜集


下一篇:linux服务器apache 一个IP,一个端口,建立多个网站的方法。