一个apache为两个不同端口的网站提供服务

看这篇博客前请先查阅  apache2.2.6 + mongrel_cluster1.0.5负载均衡  


一个台服务器开启两个httpd主进程,分别使用不同的配置文件,服务两个不同的网站。




具体步骤:

1. 从源码安装apache服务,安装路径: /usr/local/apache2.2.22


在/usr/local/apache2.2.22/conf 下创建两个配置文件httpd.conf和httpd2.conf。


httpd.conf:

ServerRoot "/usr/local/apache2.2.22"
Listen 127.0.0.1:80


LoadModule cache_module modules/mod_cache.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule rewrite_module modules/mod_rewrite.so

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>

User daemon
Group daemon

</IfModule>
</IfModule>


ServerAdmin [email protected]
ServerName 127.0.0.1:80

#DocumentRoot "/usr/local/apache2.2.22/htdocs"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>


<Directory "/usr/local/apache2.2.22/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

ErrorLog "logs/error_log"
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
   
    CustomLog "logs/access_log" common
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/usr/local/apache2.2.22/cgi-bin/"
</IfModule>


<Directory "/usr/local/apache2.2.22/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>


DefaultType text/plain

<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>


<Proxy balancer://spacecluster>
    # cluster members
    BalancerMember http://www.iche.com:4000
    BalancerMember http://www.iche.com:4001
    BalancerMember http://www.iche.com:4002
    BalancerMember http://www.iche.com:4003
</Proxy>



ExtendedStatus On
<Location /server-status>
    SetHandler server-status
</Location>

<Location /balancer-manager>
    SetHandler balancer-manager
</Location>

<VirtualHost www.iche.com:80>
    ServerName www.iche.com
    #DocumentRoot "/home/pingan/iche2/trunk/iche"
    ProxyRequests Off

    ProxyPass /balancer-manager !
    ProxyPass /server-status !
    ProxyPass / balancer://spacecluster/
    ProxyPassReverse / balancer://spacecluster/
</VirtualHost>





httpd2.conf :



ServerRoot "/usr/local/apache2.2.22"
Listen 127.0.0.1:8080


LoadModule cache_module modules/mod_cache.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule rewrite_module modules/mod_rewrite.so

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>

User daemon
Group daemon

</IfModule>
</IfModule>


ServerAdmin [email protected]
ServerName 127.0.0.1:8080

#DocumentRoot "/usr/local/apache2.2.22/htdocs"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>


<Directory "/usr/local/apache2.2.22/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

ErrorLog "logs/error_log"
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
   
    CustomLog "logs/access_log" common
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/usr/local/apache2.2.22/cgi-bin/"
</IfModule>


<Directory "/usr/local/apache2.2.22/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>


DefaultType text/plain

<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>


<Proxy balancer://spacecluster>
    # cluster members
    BalancerMember http://127.0.0.1:5000
    BalancerMember http://127.0.0.1:5001
    BalancerMember http://127.0.0.1:5002
    BalancerMember http://127.0.0.1:5003
</Proxy>



ExtendedStatus On
<Location /server-status>
    SetHandler server-status
</Location>

<Location /balancer-manager>
    SetHandler balancer-manager
</Location>

<VirtualHost 127.0.0.1:8080>
    ServerName www.iche.com
    #DocumentRoot "/home/pingan/iche2/trunk/iche_manager"
    ProxyRequests Off

    ProxyPass /balancer-manager !
    ProxyPass /server-status !
    ProxyPass / balancer://spacecluster/
    ProxyPassReverse / balancer://spacecluster/
</VirtualHost>




两个配置文件中除了监听的端口、DocumentRoot和PidFile路径不同外其他地方均可相同(根据自己需求适当修改)。


分别使用以下命令启动或关闭:


/usr/local/apache2.2.22/bin/httpd  -f  /usr/local/apache2.2.22/conf/httpd2.conf -k start|stop|restart




/usr/local/apache2.2.22/bin/httpd -f /usr/local/apache2.2.22/conf/httpd.conf  -k start|stop|restart



另外:/usr/local/apache2.2.22/bin/httpd  -k restart 命令只会导致子进程(apache用户进程,如simon用户)重新启动,而主进程(root用户)是不会重新启动的。








猜你喜欢

转载自tongxiaoming520.iteye.com/blog/1490644
今日推荐