Apache & Tomcat: ProxyPass and ProxyPassReverse
Asked Answered
H

7

17

I'am having troubles configuring Apache and Tomcat, this is the scenario:

I have an Apache Web Server, running and working normally, I can access to this one just typing:

http://localhost

Also, in this host, I have a Tomcat running and working fine; I've created a mini web-app which files are inside "prueba" directory, I can access typing:

http://localhost:8080/prueba

(I know that Apache is running in 80 port and Tomcat in 8080)

What I want to do is that througt Apache an user can access to 'pruebas'(running on Tomcat), I mean:

http://localhost/prueba

I've readen a lot of this, and I think that there are 2 ways to do this, and I've decided enabling the proxy modules(proxy and proxy_ajp, with a2enmod), also I've readed I must edit this file: sites-available/default, this is the content:

NameVirtualHost *:80
<VirtualHost *:80>
     ServerName 127.0.0.1
     DocumentRoot /var/www

     ProxyRequests Off
     ProxyPreserveHost On

     ProxyPass /static/ !
     ProxyPass / ajp://localhost:8009/
     ProxyPassReverse / ajp://localhost:8009/

.
.
.
     Alias /static/ "/apache/www/"

</VirtualHost>

But this hasn't work propperly :(

I have to say that I've tried whit many changes, ont this 2 lines, like:

     ProxyPass /prueba ajp://localhost:8009/prueba
     ProxyPassReverse /prueba ajp://localhost:8009/prueba

or

     ProxyPass / ajp://localhost:8009/prueba
     ProxyPassReverse / ajp://localhost:8009/prueba

(each time I edit the file, I restart apache)

But when I access to [http://localhost/prueba/], I have: Service Temporarily Unavailable

Has anyone knows why? Thanks in advance guys.

Pd: I'm working with apache 2.2.17 and tomcat6.

Henna answered 25/11, 2012 at 10:23 Comment(1)
For anyone stumbling across this (as I just have)--if you're seeing this in your Apache error log: ...[error] (13)Permission denied: proxy: HTTP: attempt to connect to 127.0.0.1... You can try configuring SELinux (if you're using SELinux, of course) by running this command: setsebool -P httpd_can_network_connect 1 Reference: wiki.apache.org/httpd/13PermissionDeniedAilurophobe
G
12

You have to put

 ProxyPass / ajp://localhost:8009/
 ProxyPassReverse / ajp://localhost:8009/

on your apache virtual host

Then you have to uncomment ajp listener in tomcat

<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

Then you have to configure host and context path in server.xml

REFF: http://www.ntu.edu.sg/home/ehchua/programming/howto/ApachePlusTomcat_HowTo.html

Hope this will help you..

Glucosuria answered 28/6, 2013 at 10:22 Comment(0)
A
2

ProxyPassReverse defines the URL Apache httpd should rewrite the URLs to, which would redirect to the proxied (hidden) URL. Because of this, you should change your ProxyPassReverse line to something like this:

ProxyPassReverse / http://localhost/prueba/

See also: http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html#usage

Alexipharmic answered 1/12, 2012 at 14:27 Comment(0)
P
1

Try this:

ProxyPass /prueba/ http://localhost:8009/prueba/
ProxyPassReverse /prueba/ http://localhost:8009/prueba/

and then hit the following URL from browser: http:// localhost/prueba/

note: it is mandatory to add "/prueba/"

Phonics answered 2/1, 2015 at 17:55 Comment(0)
A
0

Service not available might be coming due to SELinux ,try disabling SE Linux : setenforce 0

Annunciation answered 28/10, 2013 at 6:43 Comment(2)
Disabling SELinux is not necessary to get this to work (nor is it good practice to disable security as a quick workaround to get something to work).Ailurophobe
In fact, if SELinux is causing the issue, you can run this command:Ailurophobe
S
0

you may try adding:

ProxyPreserveHost On

From the documentation:

"When enabled, this option will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.

This option should normally be turned Off. It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated by the backend server."

Survival answered 12/5, 2015 at 1:29 Comment(0)
N
0

You stated: I can access typing:

http://localhost:8080/prueba

but the following does not work:

ProxyPass /prueba/ http://localhost:8009/prueba/

8080 != 8009

make sure your port numbers are the same

Nice answered 13/2, 2017 at 14:27 Comment(0)
L
0

Port 8009 is Tomcat so use ajp instead of http

ProxyPass /prueba/ ajp://localhost:8009/prueba/
ProxyPassReverse /prueba/ ajp://localhost:8009/prueba/
Lest answered 19/3, 2020 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.