You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joe Hansen <jo...@gmail.com> on 2011/10/19 10:07:45 UTC

AJP Errors. Apache + Tomcat

Hi,

I get the following AJP errors when I try to access a webpage after starting
Apache and Tomcat. Both Apache web server and Tomcat start up fine but I get
these errors in Apache logs and I get a 503 Service Temporarily Unavailable
message in the browser. Apparently Tomcat isn't seeing the request.

[error] (OS 10061) No connection could be made because the target machine
actively refused it.  : proxy: AJP: attempt to connect to
127.0.0.1:8009(localhost) failed
[error] ap_proxy_connect_backend disabling worker for (localhost)
[error] proxy: AJP: failed to make connection to backend: localhost

Can you please help me find out where the problem lies.

Thanks,
Joe

Environment: Apache 2.2, Tomcat 6.0.29, JDK 6, Windows 7 64-bit

/* excerpt from httpd.conf */
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin abc@gmail.com
ServerName abc.local
ServerAlias www.abc.local
ErrorLog "logs/ajp.error.log"
 RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.local [nc]
RewriteRule ^(.*)$ http://www.abclocal$1 [r=301,L]
 <Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>

ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>


/* excerpt from tomcat/conf/server.xml */
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    <Connector port="8009" protocol="AJP/1.3" redirectPort="443" />

      <Host name="localhost" appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
      </Host>

  <Host name="abc.local" appBase="c:/hosts/abc.local/webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
  </Host>

Re: AJP Errors. Apache + Tomcat

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Wed, Oct 19, 2011 at 11:47, André Warnier <aw...@ice-sa.com> wrote:
> Francis GALIEGUE wrote:
>>
>> On Wed, Oct 19, 2011 at 11:42, Francis GALIEGUE <fg...@one2team.com> wrote:
>> [...]
>>>
>>>               lsof -u $TOMCAT_USER -i tcp:8005 &>/dev/null
>>>
>>
>> Sorry, that's a non working version: forget the -u option. But with
>> only the -i, it works.
>>
>
> Thanks, very useful. I'll try that.
>

Actually, I've discovered that there's a -a option... You can do lsof
-u $TOMCAT_USER -a -i tcp:8005.

-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by André Warnier <aw...@ice-sa.com>.
Francis GALIEGUE wrote:
> On Wed, Oct 19, 2011 at 11:42, Francis GALIEGUE <fg...@one2team.com> wrote:
> [...]
>>                lsof -u $TOMCAT_USER -i tcp:8005 &>/dev/null
>>
> 
> Sorry, that's a non working version: forget the -u option. But with
> only the -i, it works.
> 

Thanks, very useful. I'll try that.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Wed, Oct 19, 2011 at 11:42, Francis GALIEGUE <fg...@one2team.com> wrote:
[...]
>
>                lsof -u $TOMCAT_USER -i tcp:8005 &>/dev/null
>

Sorry, that's a non working version: forget the -u option. But with
only the -i, it works.

-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by André Warnier <aw...@ice-sa.com>.
Francis GALIEGUE wrote:
> On Wed, Oct 19, 2011 at 11:56, Mikolaj Rydzewski <mi...@ceti.pl> wrote:
>> On Wed, 19 Oct 2011 11:42:36 +0200, Francis GALIEGUE wrote:
>>
>>> Extract from the script (note that the server port is not randomized,
>>> it should probably be):
>> Hi all,
>>
>> Why do you want to go into such deep details, like checking for particular
>> ports to be opened?
>>
>> I have httpd, mod_proxy_ajp and tomcat. mod_proxy will catch running tomcat
>> after some time. It's a matter of proper configuration how long will it
>> take.
>>
>> I guess that we all know tools like Nagios. I prefer to use them to detect
>> problems instead of hacking startup scripts.
>>
> 
> Well, this is not an option for me since my sites display a static
> page as long as long as the webapp is not ready. As the apps I manage
> take 10 seconds to start in the best of scenarios, I need to know that
> tomcat is _really_ ready to serve requests.
> 

I think that the point which Mikolaj is making, is that there must be "retry" options in 
mod_proxy_ajp, which could avoid the kind of issue which the OP mentioned in the first place.
I just don't know these options, and they may have additional side effects.  That's why I 
originally suggested a simple wait, and Francis suggested a better way, for the specific 
issue of the OP.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Wed, Oct 19, 2011 at 11:56, Mikolaj Rydzewski <mi...@ceti.pl> wrote:
> On Wed, 19 Oct 2011 11:42:36 +0200, Francis GALIEGUE wrote:
>
>> Extract from the script (note that the server port is not randomized,
>> it should probably be):
>
> Hi all,
>
> Why do you want to go into such deep details, like checking for particular
> ports to be opened?
>
> I have httpd, mod_proxy_ajp and tomcat. mod_proxy will catch running tomcat
> after some time. It's a matter of proper configuration how long will it
> take.
>
> I guess that we all know tools like Nagios. I prefer to use them to detect
> problems instead of hacking startup scripts.
>

Well, this is not an option for me since my sites display a static
page as long as long as the webapp is not ready. As the apps I manage
take 10 seconds to start in the best of scenarios, I need to know that
tomcat is _really_ ready to serve requests.

-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
 On Wed, 19 Oct 2011 11:42:36 +0200, Francis GALIEGUE wrote:

> Extract from the script (note that the server port is not randomized,
> it should probably be):

 Hi all,

 Why do you want to go into such deep details, like checking for 
 particular ports to be opened?

 I have httpd, mod_proxy_ajp and tomcat. mod_proxy will catch running 
 tomcat after some time. It's a matter of proper configuration how long 
 will it take.

 I guess that we all know tools like Nagios. I prefer to use them to 
 detect problems instead of hacking startup scripts.

-- 
 Mikolaj Rydzewski <mi...@ceti.pl>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Wed, Oct 19, 2011 at 11:27, André Warnier <aw...@ice-sa.com> wrote:
> Francis GALIEGUE wrote:
[...]
>
> Yes, that would be more reliable than my 2 seconds above.
> Although if one really wanted to split hairs in 4 parts (lenghtwise), one
> could argue that the fact that the port mentioned in <Server> is open and
> listening, does not necessarily mean that the port in the AJP Connector is
> open and listening.
>

Actually yes, it does mean that, I have double checked: connectors
start to listen before the Server port starts to listen.

> Now just by curiosity, what mechanism do you use exactly to check that the
> <server> port is listening ?  (yes, the script lines..)
>

Extract from the script (note that the server port is not randomized,
it should probably be):

----
       MAXITERS=120
        ITERS=0

        while true; do
                ITERS=$((ITERS+1))
                if [ $ITERS -gt $MAXITERS ]; then
                        echo
                        echo >&2 "BUG: Tomcat not started after
$MAXITERS seconds!"
                        exit 1
                fi

                lsof -u $TOMCAT_USER -i tcp:8005 &>/dev/null

                if [ "$?" = "0" ]; then
                        break
                fi
                echo -n .
                sleep 1
        done

        echo " Done (in $ITERS seconds)"
----

-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by André Warnier <aw...@ice-sa.com>.
Francis GALIEGUE wrote:
> On Wed, Oct 19, 2011 at 10:48, André Warnier <aw...@ice-sa.com> wrote:
>> Hi.
>>
>> The problem can also be due just to the difference in startup time between
>> Apache httpd and Tomcat.  At the time Apache httpd (and its embedded
>> mod_proxy_ajp module) try to contact Tomcat, Tomcat has possibly not yet
>> "opened" its Connector on port 8009, which causes the host to refuse a
>> connection to that port.
>>
>> In my experience anything involving Java tends to take a while to "start the
>> machinery" (it is after all a "java virtual machine").
>> In the practice thus, what we always do in such configurations, is to start
>> Tomcat first (which really means mostly "start the java virtual machine
>> which runs Tomcat")
>> , wait a couple of seconds, and then start the Apache httpd part.
>>
> 
> Actually, there is a reliable way of waiting for Tomcat to be fully
> started: wait to see the port specified in <Server> open for
> listening. Then you are sure Tomcat is fully loaded. This is what I
> use and it's very reliable.
> 

Yes, that would be more reliable than my 2 seconds above.
Although if one really wanted to split hairs in 4 parts (lenghtwise), one could argue that 
the fact that the port mentioned in <Server> is open and listening, does not necessarily 
mean that the port in the AJP Connector is open and listening.

Now just by curiosity, what mechanism do you use exactly to check that the <server> port 
is listening ?  (yes, the script lines..)




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Wed, Oct 19, 2011 at 10:48, André Warnier <aw...@ice-sa.com> wrote:
> Hi.
>
> The problem can also be due just to the difference in startup time between
> Apache httpd and Tomcat.  At the time Apache httpd (and its embedded
> mod_proxy_ajp module) try to contact Tomcat, Tomcat has possibly not yet
> "opened" its Connector on port 8009, which causes the host to refuse a
> connection to that port.
>
> In my experience anything involving Java tends to take a while to "start the
> machinery" (it is after all a "java virtual machine").
> In the practice thus, what we always do in such configurations, is to start
> Tomcat first (which really means mostly "start the java virtual machine
> which runs Tomcat")
> , wait a couple of seconds, and then start the Apache httpd part.
>

Actually, there is a reliable way of waiting for Tomcat to be fully
started: wait to see the port specified in <Server> open for
listening. Then you are sure Tomcat is fully loaded. This is what I
use and it's very reliable.

-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by André Warnier <aw...@ice-sa.com>.
Hi.

The problem can also be due just to the difference in startup time between Apache httpd 
and Tomcat.  At the time Apache httpd (and its embedded mod_proxy_ajp module) try to 
contact Tomcat, Tomcat has possibly not yet "opened" its Connector on port 8009, which 
causes the host to refuse a connection to that port.

In my experience anything involving Java tends to take a while to "start the machinery" 
(it is after all a "java virtual machine").
In the practice thus, what we always do in such configurations, is to start Tomcat first 
(which really means mostly "start the java virtual machine which runs Tomcat")
, wait a couple of seconds, and then start the Apache httpd part.




Joe Hansen wrote:
> I uninstalled Tomcat and installed a newer version (6.0.33) and the problem
> disappeared. It is strange because the config files are the same.
> 
> On Wed, Oct 19, 2011 at 2:16 AM, <jo...@gniffelnieuws.net> wrote:
> 
>> Hi
>>> I get the following AJP errors when I try to access a webpage after
>> ztarting
>>> Apache and Tomcat. Both Apache web server and Tomcat start up fine
>>> but I get these errors in Apache logs and I get a 503 Service
>>> Temporarily Unavailable message in the browser. Apparently Tomcat
>>> isn't seeing the request.
>>>
>>> [error] (OS 10061) No connection could be made because the target machine
>>> actively refused it.  : proxy: AJP: attempt to connect to
>>> 127.0.0.1:8009(localhost) failed
>>> [error] ap_proxy_connect_backend disabling worker for (localhost)
>>> [error] proxy: AJP: failed to make connection to backend: localhost
>>>
>>> Can you please help me find out where the problem lies.
>>>
>> Have you checked the port is listening? (netstat -an) and the firewall
>> permits the connection (telnet localhost 8009)
>>
>> John
>>
>> --
>> /(bb|[^b]{2})/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AJP Errors. Apache + Tomcat

Posted by Joe Hansen <jo...@gmail.com>.
I uninstalled Tomcat and installed a newer version (6.0.33) and the problem
disappeared. It is strange because the config files are the same.

On Wed, Oct 19, 2011 at 2:16 AM, <jo...@gniffelnieuws.net> wrote:

> Hi
> >
> > I get the following AJP errors when I try to access a webpage after
> ztarting
> > Apache and Tomcat. Both Apache web server and Tomcat start up fine
> > but I get these errors in Apache logs and I get a 503 Service
> > Temporarily Unavailable message in the browser. Apparently Tomcat
> > isn't seeing the request.
> >
> > [error] (OS 10061) No connection could be made because the target machine
> > actively refused it.  : proxy: AJP: attempt to connect to
> > 127.0.0.1:8009(localhost) failed
> > [error] ap_proxy_connect_backend disabling worker for (localhost)
> > [error] proxy: AJP: failed to make connection to backend: localhost
> >
> > Can you please help me find out where the problem lies.
> >
> Have you checked the port is listening? (netstat -an) and the firewall
> permits the connection (telnet localhost 8009)
>
> John
>
> --
> /(bb|[^b]{2})/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: AJP Errors. Apache + Tomcat

Posted by jo...@gniffelnieuws.net.
Hi
> 
> I get the following AJP errors when I try to access a webpage after 
ztarting
> Apache and Tomcat. Both Apache web server and Tomcat start up fine 
> but I get these errors in Apache logs and I get a 503 Service 
> Temporarily Unavailable message in the browser. Apparently Tomcat 
> isn't seeing the request.
> 
> [error] (OS 10061) No connection could be made because the target machine
> actively refused it.  : proxy: AJP: attempt to connect to
> 127.0.0.1:8009(localhost) failed
> [error] ap_proxy_connect_backend disabling worker for (localhost)
> [error] proxy: AJP: failed to make connection to backend: localhost
> 
> Can you please help me find out where the problem lies.
> 
Have you checked the port is listening? (netstat -an) and the firewall 
permits the connection (telnet localhost 8009)

John

--
/(bb|[^b]{2})/


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org