Linux下Apache配置虚拟主机

在/etc/hosts添加域名解析
127.0.0.1   www.king.org
127.0.0.1   blog.king.org
127.0.0.1   bbs.king.org

1)配置基于域名的虚拟主机

在httpd.conf中启动httpd-vhosts.conf

Include conf/extra/httpd-vhosts.conf

添加一下内容,对虚拟主机的目录授权


    Options  FollowSymLinks
    AllowOverride None
    Require all granted




    Options  FollowSymLinks
    AllowOverride None
    Require all granted


    Options  FollowSymLinks
    AllowOverride None
    Require all granted


2.在conf/extra/httpd-vhosts.conf中添加以下内容


    ServerAdmin [email protected]
    DocumentRoot "/var/www/web"
    ServerName www.king.org
    ServerAlias king.org
    ErrorLog "logs/web-error_log"
    CustomLog "logs/web-access_log" common




    ServerAdmin [email protected]
    DocumentRoot "/var/www/bbs"
    ServerName bbs.king.org
    ServerAlias bbs.org
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common




    ServerAdmin [email protected]
    DocumentRoot "/var/www/blog"
    ServerName blog.king.org
    ServerAlias blog.org
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common


2.基于端口的虚拟主机

在httpd.conf中添加两行

Listen 8000

Listen 9000


    ServerAdmin [email protected]
    DocumentRoot "/var/www/web"
    ServerName www.king.org
    ServerAlias king.org
    ErrorLog "logs/web-error_log"
    CustomLog "logs/web-access_log" common




    ServerAdmin [email protected]
    DocumentRoot "/var/www/bbs"
    ServerName bbs.king.org
    ServerAlias bbs.org
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common




    ServerAdmin [email protected]
    DocumentRoot "/var/www/blog"
    ServerName blog.king.org
    ServerAlias blog.org
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common


httpd -k graceful

netstat -tlunp|grep -E "8000|9000"
tcp        0      0 :::8000                     :::*                        LISTEN      89128/httpd         
tcp        0      0 :::9000                     :::*                        LISTEN      89128/httpd 


3.基于IP的虚拟主机

ifconfig eth0:0 192.168.1.118/24 up


    ServerAdmin [email protected]
    DocumentRoot "/var/www/web"
    ServerName 192.168.1.115
    ServerAlias king.org
    ErrorLog "logs/web-error_log"
    CustomLog "logs/web-access_log" common




    ServerAdmin [email protected]
    DocumentRoot "/var/www/bbs"
    ServerName 192.168.1.118
    ServerAlias bbs.org
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common

你可能感兴趣的:(apache,虚拟主机,域名,linux,Linux服务及故障排除)