Apache 多站点设置

查看虚拟主机列表:
a2query -s
apache2ctl -S
1.
/etc/apache2/sites-available/目录下,默认放了两个配置文件,(000-default.conf 网站配置文件 default-ssl.conf  ssl协议配置文件),这个目录下存放所有网站的配置信息,如果你添加了网站,需要在这里添加域名配置,命名方式为域名.conf 例如:test.com.conf

2.
root@debian:/var/www# pwd
/var/www
root@debian:/var/www# ls
html  test1.com  test.com
每个文件夹是网站的一个路径
里面放置的网页

检查apache  配置apachectl configtest


3.配置文件
root@debian:/etc/apache2/sites-available# ls
000-default.conf  default-ssl.conf  test1.com.conf  test.com.conf
root@debian:/etc/apache2/sites-available# cat test.com.conf 
#Alias "/test" "/www/test"

    ServerName test.com
    ServerAlias www.test.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/test.com

    
        Options -Indexes +FollowSymLinks
        AllowOverride All
    

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined



4.
a2ensite test.com.conf      启动配置文件
service apache2 restart       启动apache    
  
a2dissite test.com.conf    取消配置文件运行


root@debian:/etc/apache2/sites-available# cat /etc/hosts
127.0.0.1	localhost
127.0.1.1	debian

127.0.0.1	test.com
127.0.0.1	www.test.com

127.0.0.1	test.com
127.0.0.1	test.com
127.0.0.1	www.test1.com
127.0.0.1	test1.com
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

代理到:Tomcat

proxy_module_http:


    ServerName test1.com
    ProxyVia On
    ProxyRequests Off
    ProxyPreserveHost On
   
      Require all granted
   

    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/
   
    Require all granted
   

    #ServerAlias www.test1.com
    #ServerAdmin [email protected]
    #DocumentRoot /var/www/test1.com

    #
    #   Options -Indexes +FollowSymLinks
    #    AllowOverride All
    #

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

 

 

proxy_module_ajp模式:

root@debian:/etc/apache2/sites-available# cat test1.com.conf 
#Alias "/test" "/www/test"

    ServerName test1.com
    ProxyVia On
    ProxyRequests Off
    ProxyPreserveHost On
   
      Require all granted
   

    ProxyPass / ajp://127.0.0.1:8080/
    ProxyPassReverse / ajp://127.0.0.1:8080/
   
    Require all granted
   

    #ServerAlias www.test1.com
    #ServerAdmin [email protected]
    #DocumentRoot /var/www/test1.com

    #
    #   Options -Indexes +FollowSymLinks
    #    AllowOverride All
    #

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

你可能感兴趣的:(运维)