apache的虚拟主机分为三种:
基于ip的虚拟主机
基于端口的虚拟主机
基于域名的虚拟主机
基于域名的虚拟主机:
对apache做虚拟主机主要是修改/application/apache/conf/extra目录下面的httpd-vhosts.conf 文件
NameVirtualHost *:80
#
<VirtualHost *:80>
ServerAdmin 15259513**@qq.com 管理邮箱
DocumentRoot "/var/html/www/" 该域名要访问的主页的目录
ServerName www.abc.com 域名
ServerAlias etiantian.com 域名的别名
ErrorLog "|/usr/local/sbin/cronolog /var/logs/apache/%Y/%m/error_www_%Y%m%d.log"
CustomLog "|/usr/local/sbin/cronolog /var/logs/apache/%Y/%m/access_www_%Y%m%d.log" combined 对日志做日志轮询。
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 1525951343@qq.com
DocumentRoot "/var/html/blog/"
ServerName blog.abc.com
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 1525951343@qq.com
DocumentRoot "/var/html/bbs/"
ServerName bbs.abc.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
更改好httpd-vhosts.conf文件后需要在apache主配置文件进行授权。
vim httpd.conf 在该配置文件添加以下内容:
</IfModule>
<Directory "/var/html/"> 用户访问主页的目录
Options -Indexes FollowSymLinks -Indexes 不显示apache的目录结构
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Include conf/extra/httpd-vhosts.conf 将这行的注释去掉。
============================================================
基于不同端口的虚拟主机:
对apache做虚拟主机主要是修改/application/apache/conf/extra目录下面的httpd-vhosts.conf 文件
NameVirtualHost *:80
NameVirtualHost *:8000
NameVirtualHost *:8080
#
# 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 *:80>
ServerAdmin 1525951343@qq.com
DocumentRoot "/var/html/www/"
ServerName www.etiantian.com
ServerAlias etiantian.com
ErrorLog "|/usr/local/sbin/cronolog /var/logs/apache/%Y/%m/error_www_%Y%m%d.log"
CustomLog "|/usr/local/sbin/cronolog /var/logs/apache/%Y/%m/access_www_%Y%m%d.log" combined
</VirtualHost>
<VirtualHost *:8000>
ServerAdmin 1525951343@qq.com
DocumentRoot "/var/html/blog/"
ServerName blog.etiantian.com
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin 1525951343@qq.com
DocumentRoot "/var/html/bbs/"
ServerName bbs.etiantian.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
更改好httpd-vhosts.conf文件后需要在apache主配置文件进行授权。
vim httpd.conf 在该配置文件添加以下内容:
</IfModule>
<Directory "/var/html/"> 用户访问主页的目录
Options -Indexes FollowSymLinks -Indexes 不显示apache的目录结构
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Include conf/extra/httpd-vhosts.conf 将这行的注释去掉。
原文地址:http://12150465.blog.51cto.com/12140465/1932711