CentOS6 Apache配置详解(中)

CentOS6 Apache配置详解()


#######################################################################
虚拟主机
Apache支持基于ip的虚拟主机和基于域名的虚拟主机
#######################################################################
1.基于IP,分两种情况,
ip相同,端口不同
vi /etc/httpd/cond.d/virtual.conf


    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all


    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all


Listen 8000
Listen 8001


    ServerAdmin  liujun_ok@hotmail.com
    DocumentRoot /var/www/test2
    DirectoryIndex    index.html
    ErrorLog     /var/log/httpd/test2.jlive.com_err
    CustomLog   /var/log/httpd/test2.jlive.com_log  combined


    ServerAdmin  liujun_ok@hotmail.com
    DocumentRoot /var/www/test1
    DirectoryIndex    index.html
    ErrorLog     /var/log/httpd/test1.jlive.com_err
    CustomLog   /var/log/httpd/test1.jlive.com_log  combined

#######################################################################
端口相同,ip不同

    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all


    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all



    ServerAdmin  liujun_ok@hotmail.com
    DocumentRoot /var/www/test2
    ServerName      192.168.100.2:80
    DirectoryIndex    index.html
    ErrorLog     /var/log/httpd/test2.jlive.com_err
    CustomLog   /var/log/httpd/test2.jlive.com_log  combined


    ServerAdmin  liujun_ok@hotmail.com
    DocumentRoot /var/www/test1
    ServerName      192.168.100.1:80
    DirectoryIndex    index.html
    ErrorLog     /var/log/httpd/test1.jlive.com_err
    CustomLog   /var/log/httpd/test1.jlive.com_log  combined


#######################################################################
基于域名

1.必须用NameVirtualHost指定哪个ip地址负责响应对虚拟主机的请求

NameVirtualHost *:80            本机任何接口的80端口所指定的虚拟主机
NameVirtualHost *:8000            本机任何接口的8000端口所指定的虚拟主机
NameVirtualHost 192.168.100.2:80     192.168.100.2的80端口负责响应

Listen 8000
Listen 8001

规范目录权限

    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all


    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all


设置虚拟主机

    ServerAdmin  liujun_ok@hotmail.com
    DocumentRoot /var/www/html
    ServerName      www.jlive.com



    ServerAdmin  liujun_ok@hotmail.com
    DocumentRoot /var/www/test1
    ServerName      test1.jlive.com:8000
    DirectoryIndex    index.html
    ErrorLog     /var/log/httpd/test1.jlive.com_err
    CustomLog   /var/log/httpd/test1.jlive.com_log  combined

Listen 8000

    ServerAdmin  liujun_ok@hotmail.com
    DocumentRoot /var/www/test2
    ServerName      test2.jlive.com:8001
    DirectoryIndex    index.html
    ErrorLog     /var/log/httpd/test2.jlive.com_err
    CustomLog   /var/log/httpd/test2.jlive.com_log  combined

######################################################################
注意:
    最低限度有ServerName DocumentRoot
    原本的主机名也要同时写入



######################################################################
动态虚拟主机技术
确保加载mod-vhost-alias模块,可以基于域名也可基于ip

基于ip
UseCanonicalName DNS

指定虚拟主机目录
VirtualDocumentRoot    /var/www/dynamicvhost/%0/html
%将被虚拟主机的名称所代替,如,一台虚拟主机的域名为www.vhost.net,则系统会创建/var/www/dynamicvhost/www.vhost.net/html目录作为其主目录.

对于cgi目录,则可使用VirtualScriptAlias
VirtualScriptAlias    /var/www/dynamicvhost/%0/cgi-bin


UseCanonicalName DNS
VirtualDocumentRoot    /var/www/dynamicvhost/%0/html
VirtualScriptAlias    /var/www/dynamicvhost/%0/cgi-bin
######################################################################
基于域名
UseCanonicalName off
VirtualDocumentRoot    /var/www/dynamicvhost/%0/html
VirtualScriptAlias    /var/www/dynamicvhost/%0/cgi-bin
######################################################################
动态虚拟主机的一个缺点就是用户仅能对所有主机设置一个日志,但用户可以创建自己的shell脚本来分离




#######################################################################
启动用户的个人网站
#######################################################################

    #UserDir disabled
    UserDir public_html




    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
   
        Order allow,deny
        Allow from all
   
   
        Order deny,allow
        Deny from all
   

原文地址:https://www.cnblogs.com/lixuebin/p/10814549.html