linux系统apache配置virtualhost

系统版本:centos 5.10

apache版本:2.4.10

apache虚拟主机支持多种形式,比如单ip多网站、多ip单网站等,官网有说明,这里多说几点:

apache 2.4.10配置文件都在跟目录conf文件夹内,主配置文件httpd.conf里面已经没有vhost相关配置内容,需要将

Include conf/extra/httpd-vhosts.conf 改成 Include conf/extra/httpd-vhosts.conf

之后在conf/extra/里面找到配置文件httpd-vhosts.conf,进行配置添加相应的修改

端口相同,不同域名访问

<VirtualHost *:80>;
# ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/example1"
ServerName 直接写域名
</VirtualHost>

<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/example2"
ServerName 直接写域名
</VirtualHost>

相同域名,不同端口访问

<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/www"
ServerName 直接写域名
</VirtualHost>

<VirtualHost *:8081>
# ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/www"
ServerName 直接写域名
</VirtualHost>

无论是上面哪种方式,记得在httpd.conf里面配置DocumentRoot的访问权限,如下

<Directory "上面的DocumentRoot">
#
# 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/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks

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

#
# Controls who can get stuff from this server.
#
Require all granted

之后重启apache,ok,单一主机配置多网站搭建完成

发表评论

%d 博主赞过: