[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Run two instances of apache2 on the same machine?



Hi all,

The history of how I got to the point of needing to run two instances of
apache2 is further below. Feel free to ignore it all and concentrate on
this question, thanks :-)

How do I start two instances of apache2? The apache2 binary seems to be
hardwired to stop this:

apache2 -D proxy -k start
(works OK)

apache2 -D server -k start
httpd (pid xxxx) already running

even hard linking apache2 to another filename and running that instead
doesn't work.

My approach is simple. ports.conf contains:

<IfDefine proxy>
  Listen 80
</IfDefine>

<IfDefine server>
  Listen 81
</IfDefine>

And rewrite.conf contains:

<IfDefine proxy>
  <VirtualHost *>
    ServerName www2.cpag.org.nz
    RewriteEngine On
    RewriteLog /var/log/apache2/rewrite.log
    RewriteLogLevel 9
    RewriteRule ^/(.*) http://www2.cpag.org.nz:81/cgi-bin/load/cpag$1 [P]
  </VirtualHost>
</IfDefine>

Thus when someone connects to www2.cpag.org.nz on port 80 the Apache
server will act as a proxy to the second Apache server running on port
81.

But I just can't get more than one instance of apache2 to start. Thanks
for some (Debian-specific) advice.

If you want an answer to the question "Why are your trying to run two
instances of Apache?" then read on.



A URL rewriting job that I thought would be a cinch has turned out to be
more difficult than expected. The post I made to
comp.infosystems.www.servers.unix yesterday and the rest of the
discussion is pasted at the end of this email because it is not yet
archived by Google Groups.

The reply was that it looks to be an Apache bug. I'm not so sure about
that according to the documentation. Your input would be appreciated.
However I'd also like to take a different approach that should work. 

As I stated below I wish to rewrite a URL like this (here's a different
example): 

http://domain/about

...to this: 
http://domain/cgi-bin/<script>/cpag/about

...without using a client-side redirect (because the second address is
ugly). The entire web site is accessed through a CGI program using
Apache to connect to the outside world.

about, etc. may or may not be real files or directories. That's for the
CGI program called <script> to determine. 

After hours of permutations I couldn't get any rewrite rule to work. And
if you read the quotes from my post below URL-->URL rewriting (instead
of URL-->File rewriting) may not be supported by the present API (of
2.0.40). 

It also appears that a mod_proxy way that you might think would work is
not supported and considered silly (again see below). 

Because of this it looks like I'm going to have to run two instances of
Apache. One instance of Apache will be on port 80 and act as a proxy
server and rewriter to the second apache server on port 81. I could also
offload this proxy role to another machine, but I'd like the machine to
be self-sufficient. 

Regards, 
Adam 




Original post to comp.infosystems.www.servers.unix follows: 

Hi all,

I'm trying to rewrite the base directory of a URL to a virtual cgi-bin
path (so it will be hidden). Here's an example: Client enters
http://domain/about in their web browser and this is mapped to
http://domain/cgi-bin/load/about. about doesn't actually exist as a file.
It's part of the path that is passed to the CGI script called load. To
reiterate, load is the CGI script, the rest of the path information is
available as the environment variable PATH_INFO.

I've overcome the problem of an infinite loop. However after the URL is
rewritten it doesn't appear to act as an original URL should (that is I
want to map a URL onto a URL, not onto a file which won't exist).

I'm running the CVS version of Apache 2.0.40. The latests mod_rewrite docs
state: http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html

   1.  Although mod_rewrite rewrites URLs to URLs, URLs to filenames and
   even filenames to filenames, the API currently provides only a
   URL-to-filename hook. In Apache 2.0 the two missing hooks will be added
   to make the processing more clear. But this point has no drawbacks for
   the user, it is just a fact which should be remembered: Apache does
   more in the URL-to-filename hook than the API intends for it.

Does this mean that I can't currently rewrite a URL to a URL using a
config file?

If so it appears I have to achieve this using mod_proxy. But rewriting to
the same server doesn't appear to be supported either:

Inside per-server configuration (httpd.conf) for request ``GET
/somepath/pathinfo'':

Given Rule                                      Resulting Substitution
---------------------------------------------- ------------------------
...
^/somepath(.*) /otherpath$1 [P]             not supported, because silly!
^/somepath(.*) http://thishost/otherpath$1 [P]  not supported, b/c silly!

The thing is it doesn't appear to be silly. It would allow parts of a URL
to be hidden from the end user.

Am I understanding this correctly? Is the only way to map a URL to a URL
by setting up a separate Apache proxy server on a different port or
machine?

Thanks,
Adam




Adam Warner <usenet@consulting.net.nz> wrote:
> Hi all,

> I'm trying to rewrite the base directory of a URL to a virtual cgi-bin
> path (so it will be hidden). Here's an example: Client enters
> http://domain/about in their web browser and this is mapped to
> http://domain/cgi-bin/load/about. about doesn't actually exist as a
> file. It's part of the path that is passed to the CGI script called
> load. To reiterate, load is the CGI script, the rest of the path
> information is available as the environment variable PATH_INFO.

> I've overcome the problem of an infinite loop. However after the URL is
> rewritten it doesn't appear to act as an original URL should (that is I
> want to map a URL onto a URL, not onto a file which won't exist).

I'm going to ignore the rest of your message for now, because it appears
you are making things too complicated.  Please try something like

RewriteEngine On
RerwiteRule ^/about /cgi-bin/load/about [PT]

Note the [PT] is necessary to have ScriptAlias processing work properly. 
If that doesn't work, please explain exactly what the results are
(including any log messages) and exactly you would like to happen.

-- 
Joshua Slive
news@slive.ca
Apache HTTP Server Users Mailing List: http://httpd.apache.org/userslist.html




Hi Joshua Slive,

> Adam Warner <usenet@consulting.net.nz> wrote:
>> Hi all,
> 
>> I'm trying to rewrite the base directory of a URL to a virtual cgi-bin
>> path (so it will be hidden). Here's an example: Client enters
>> http://domain/about in their web browser and this is mapped to
>> http://domain/cgi-bin/load/about. about doesn't actually exist as a
>> file. It's part of the path that is passed to the CGI script called
>> load. To reiterate, load is the CGI script, the rest of the path
>> information is available as the environment variable PATH_INFO.
> 
>> I've overcome the problem of an infinite loop. However after the URL is
>> rewritten it doesn't appear to act as an original URL should (that is I
>> want to map a URL onto a URL, not onto a file which won't exist).
> 
> I'm going to ignore the rest of your message for now, because it appears
> you are making things too complicated.  Please try something like
> 
> RewriteEngine On
> RerwiteRule ^/about /cgi-bin/load/about [PT]
> 
> Note the [PT] is necessary to have ScriptAlias processing work properly.
> If that doesn't work, please explain exactly what the results are
> (including any log messages) and exactly you would like to happen.

Thanks for the reply Joshua. Perhaps by ignoring the rest of my message
you may have missed the point (but it's also possible I'm still on the
wrong track). As a solution you propose to use the passthrough handler:

   This flag forces the rewriting engine to set the uri field of the
   internal request_rec structure to the value of the filename field. This
   flag is just a hack to be able to post-process the output of
   RewriteRule directives by Alias, ScriptAlias, Redirect, etc. directives
   from other URI-to-filename translators.

This is a URL to filename translator. I don't want to translate from a URL
to a filename. I need to translate from a URL to a URL that is then
processed as if the client entered the longer URL itself (and without
using a visible redirect).

I tried this rewrite:

   <VirtualHost *>
   ServerName www2.cpag.org.nz
   RewriteEngine On
   RewriteLog /var/log/apache2/rewrite.log
   RewriteLogLevel 9
   RewriteRule ^/cpag /cgi-bin/load/cpag [PT]
   </VirtualHost>

Like always happens there is a 404 error because the filename does not
exist. This is clear from the rewrite log:

   init rewrite engine with requested uri /cpag

   applying pattern '^/cpag' to uri '/cpag'

   rewrite /cpag -> /cgi-bin/load/cpag

   forcing '/cgi-bin/load/cpag' to get passed through to next API
   URI-to-filename handler

   init rewrite engine with requested uri /error/HTTP_NOT_FOUND.html.var

This doesn't work because the URL is not supposed to be mapped to a
physical filename. I believe I need to pass the URI to a URI-to-URI
handler, not a URI-to-filename handler. Which is why it seems that proxy
rewriting is necessary (but unsupported as silly).

I hope this clarifies things. We may yet find another way to get this to
work other than having to run a separate instance of apache as a proxy
redirector to another port.

Regards,
Adam




Adam Warner <usenet@consulting.net.nz> wrote:
> This is a URL to filename translator. I don't want to translate from a
> URL to a filename. I need to translate from a URL to a URL that is then
> processed as if the client entered the longer URL itself (and without
> using a visible redirect).

RewriteRule should be able to translate URL to URL without using a proxy.

> I tried this rewrite:

>    <VirtualHost *>
>    ServerName www2.cpag.org.nz
>    RewriteEngine On
>    RewriteLog /var/log/apache2/rewrite.log RewriteLogLevel 9
>    RewriteRule ^/cpag /cgi-bin/load/cpag [PT] </VirtualHost>

> Like always happens there is a 404 error because the filename does not
> exist. This is clear from the rewrite log:

My guess (and it is only a guess) is that apache is not doing the proper
PATH_INFO checks on the mod_rewrite sub-request.  If you don't get any
other responses, I suggest you file a bug report including the exact
configuration and exact error messages you are getting.

-- 
Joshua Slive
news@slive.ca
Apache HTTP Server Users Mailing List: http://httpd.apache.org/userslist.html




Joshua Slive <news@slive.ca> wrote:
>>    RewriteRule ^/cpag /cgi-bin/load/cpag [PT]

>> Like always happens there is a 404 error because the filename does not
>> exist. This is clear from the rewrite log:

> My guess (and it is only a guess) is that apache is not doing the proper
> PATH_INFO checks on the mod_rewrite sub-request.  If you don't get any
> other responses, I suggest you file a bug report including the exact
> configuration and exact error messages you are getting.

Incidentally, if you can modify your load script, you should be able to
get it to work by using the QUERY_STRING in place of PATH_INFO as in
RewriteRule ^/cpag /cgi-bin/load?cpag [PT]

-- 
Joshua Slive
news@slive.ca
Apache HTTP Server Users Mailing List: http://httpd.apache.org/userslist.html




Reply to: