当前位置: 首页>>技术教程>>正文


如何在同一系统上运行两个Apache实例(Ubuntu)

,

问题描述

如何在同一系统上运行apache的两个实例,并彼此独立地启动和停止它们。任何帮助或线索表示赞赏。

最佳思路

我想这可能就是您要寻找的http://wiki.apache.org/httpd/RunningMultipleApacheInstances

供参考以上链接中的内容

1)在您的服务器上安装Apache

sudo apt-get install apache2
sudo apt-get install libapache2-mod-perl2
sudo apt-get install other-lib-mods-needed

2)为要运行的每个实例配置单独的apache配置

对于Ubuntu,它应该位于/etc /apache2中对于每个需要在不同端口上侦听的实例,基本上。

# httpd-proxy.conf
Listen 80
ErrorLog /var/log/httpd-proxy-error.log
LoadModule proxy_module                 libexec/apache22/mod_proxy.so
LoadModule proxy_http_module            libexec/apache22/mod_proxy_http.so

# httpd-perl.conf
Listen 81
ErrorLog /var/log/httpd-perl-error.log
LoadModule perl_module                  libexec/apache22/mod_perl.so

# httpd-python.conf
Listen 82
ErrorLog /var/log/httpd-python-error.log
LoadModule python_module                libexec/apache22/mod_python.so

# httpd-php.conf
Listen 83
ErrorLog /var/log/httpd-php-error.log
LoadModule php5_module                        libexec/apache22/libphp5.so

在此示例中,将运行4个不同的实例,每个实例处理不同的模块类型,即一个用于perl,一个用于python等。

现在,您还需要在代理实例中配置虚拟主机,以便每当有针对Subversion DAV服务器的请求到达时,该请求便被传递到’python-dav’ apache中,而对wordpress博客的请求将传递到’php’ apache实例中。让我们再次编辑’httpd-proxy.conf’:

# httpd-proxy.conf
NameVirtualHost *:80
<VirtualHost *:80>
 DocumentRoot /www/wordpress
 ServerName blog.company.com
 ProxyPass / http://localhost:83/
 ProxyPassReverse / http://localhost:83/
 [... additional directives here ... ]
</VirtualHost>
<VirtualHost *:80>
 DocumentRoot /www/svn
 ServerName svn.company.com
 ProxyPass / http://localhost:82/
 ProxyPassReverse / http://localhost:82/
 [... additional directives here ... ]
</VirtualHost>
# you get the idea ...  

2b)测试所有内容至此,我们完成了配置,现在我们需要启动所有apache实例,并测试一切是否按预期工作。当然,您可以使用’apachectl’来执行此操作,例如

 /usr/local/sbin/apachectl -f /usr/local/etc/apache22/proxy-httpd.conf configtest
 /usr/local/sbin/apachectl -f /usr/local/etc/apache22/proxy-httpd.conf start
 /usr/local/sbin/apachectl -f /usr/local/etc/apache22/perl-httpd.conf configtest
 /usr/local/sbin/apachectl -f /usr/local/etc/apache22/perl-httpd.conf start
 # and so on ...

3)配置初始化脚本以使用适当的配置文件启动apache

链接的资源提供了有关编辑rc.conf文件的更多详细信息,但与处理Ubuntu的工作特别相关,因此我将在下面重点介绍这两个部分。

The ‘/etc/rc.conf’ in FreeBSD is the master file containing the system configuration >information. This file is read after booting the kernel, and serves to launch services, >daemons, set up network interfaces, etc. For our recipe we will be enabling the apache >server, listing the available instances (profiles), their configuration files, and >telling FreeBSD which of these need to be run (enabled) after booting the system.

# /etc/rc.conf
apache22_enable="YES"
apache22_profiles="proxy perl python php"

# the apache proxy instance
apache22_proxy_configfile="/usr/local/etc/apache22/httpd-proxy.conf"
apache22_proxy_enable="YES"

# the apache perl instance
apache22_perl_configfile="/usr/local/etc/apache22/httpd-perl.conf"
apache22_perl_enable="YES"

# the apache python instance
apache22_python_configfile="/usr/local/etc/apache22/httpd-python.conf"
apache22_python_enable="YES"

# the apache php instance
apache22_php_configfile="/usr/local/etc/apache22/httpd-php.conf"
apache22_php_enable="YES"

When these profiles are configured in /etc/rc.conf, and enabled, they will be started >after successfully booting the system. If you want to declare a profile but you only want >to start the corresponding apache instance manually, you can just edit ‘/etc/rc.conf’ and >say, e.g. :

 # the apache php instance
 apache22_php_configfile="/usr/local/etc/apache22/httpd-php.conf"
 apache22_php_enable="NO"

Later, you can start/stop any apache instance manually using just the profile name >(proxy, perl, python, php), like this:

 /usr/local/etc/rc.d/apache22 start php
 /usr/local/etc/rc.d/apache22 stop perl
 ...

3b)对于Ubuntu

I’m not sure this will be similar (and painless) as in the case of FreeBSD (see section on rc.conf above). The apache rc scripts installed with the apache port in FreeBSD have been aware of the possibility of different profiles for years now.

Recently, the Ubuntu/Debian init scripts (e.g. /etc/init.d/apache2) have been updated to support multiple instances of apache (e.g. multiple configurations, named /etc/apache2-$SUFFIX). Depending on the release of Ubuntu/Debian you’re using you may be lucky … or not.

The feature appeared in Debian in version 2.2.14-6 in Feb 2010: http://lists.alioth.debian.org/pipermail/pkg-apache-commits/2010-February/000295.html

In Ubuntu, the apache2 packages in Maverick (10.10) contain these patches: http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.2.16-1ubuntu3.1/changelog

However the Lucid (10.04, Long Term Support Release) apache2 apparently do not: http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.2.14-5ubuntu8.4/changelog

Documentation can be found in /usr/share/doc/apache2/README.multiple-instances

次佳思路

感谢您的详细回答,但后来我发现此链接http://someofmylearnings.wordpress.com/2011/07/02/multiple-apache2-instances-on-ubuntu/此过程非常简单。

当我们安装Apache时,有一个/usr/share/doc/apache2.2-common/README.multiple-instances文件,您可以通过它来了解创建Apache实例到底需要做什么。

在同一目录中,有一个examples目录,其中包含一个名为setup-instance的脚本,可用于创建Apache实例。因此,要创建另一个Apache实例,需要做的就是:

sh /usr/share/doc/apache2.2-common/examples/setup-instance web-server1

其中web-server1是后缀。也就是说,默认情况下会将“apache2-”附加到实例名称。

这将创建一个包含所有配置文件的新目录/etc/apache-web-server1。它还将创建/etc/init.d/apache-web-server1,您可以使用它来启动新的Apache实例。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/8307.html,未经允许,请勿转载。