Link to home
Start Free TrialLog in
Avatar of Shaun Wingrin
Shaun WingrinFlag for South Africa

asked on

Tomcat / apache port forwarding... CentOs server

Say,
We've apache listening on port 80 and don't wish to open an additional port.
an instance of Tomcat is listening on port 1234 say.
How do we setup apache to fwd to port 1234 tomcat
I believe httpd.conf needs to be edited.
The application JapserReportsServer, uses tomcat on above port.
Currently there is a url to the apache webserver.
We would need a path off the url to point to apache and hence tomcat port 1234.

PS pls explain function of tomcat versus apache.
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India image

without any changes in httpd.conf, you can call the other port with same path..

For example

www.example.com  //for apache
www.example.com:1234  //for tomcat
Avatar of Shaun Wingrin

ASKER

Pls see my qu:
"don't wish to open an additional port"
PS pls explain function of tomcat versus apache.
ASKER CERTIFIED SOLUTION
Avatar of tvedtem
tvedtem
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tx TVEDTEM!

What about httpd.conf file? Can this be used?

With:   ProxyPass and   ProxyPassReverse ?
My code below in httpd.conf below returns website unknown .... when goto www.abc.xyz.co.za

<VirtualHost *:80>
  DocumentRoot /home/jasperreports-server-cp-5.0.0/apache-tomcat/webapps/jasperserver
  ServerName www.abc.xyz.co.za

  ErrorLog logs/messaging_error_log
  CustomLog logs/messaging_access_log common
  ProxyPreserveHost On
 # ProxyPass / ajp://127.0.0.1:8009/
 # ProxyPass / ajp://localhost:8009/
#  ProxyPassReverse / ajp://localhost:8009/
#   ProxyPass  /        http://x.x.x.100:991/
#   ProxyPassReverse /  http://x.x.x.100:991/
    ProxyPass  /        http://127.0.0.1:991/
    ProxyPassReverse /  http://127.0.0.1:991/
</VirtualHost>

I've tried with this to:
  ProxyPass  /        http://x.x.x.100:991/
   ProxyPassReverse /  http://x.x.x.100:991/
#    ProxyPass  /        http://127.0.0.1:991/
  #  ProxyPassReverse /  http://127.0.0.1:991/
Yes,  you can use ProxyPass (this is mod_proxy) instead.  If you don't need any of mod_jk's load balancing etc, this is probably easier and simpler (therefore, better!)

The next step is to establish whether you've reached Tomcat, or not (in other words, whether your IP and port numbers are correct for the Tomcat/Jasper server)

Without knowing exactly what you're seeing (i.e. what 'website unknown' is) it's hard to tell from here.  If it's a Tomcat error page then you've done the first bit (forwarding to Tomcat)

Have a look in the Tomcat access and error logs to see if you can see the HTTP requests coming in, and go from there.

If you can't see them, you need to confirm that the IP and ports are correct, and that Tomcat is actually running.
Tx. The error is a redirect to my OpenDNS site to say site loading too slow or unavailable....
What is path to logs you refer to?
Is this needed:   DocumentRoot /home/jasperreports-server-cp-5.0.0/apache-tomcat/webapps/jasperserver
?
Do I use the local host or pub IP's above ?

#   ProxyPass  /        http://x.x.x.100:991/
#   ProxyPassReverse /  http://x.x.x.100:991/
    ProxyPass  /        http://127.0.0.1:991/
    ProxyPassReverse /  http://127.0.0.1:991/
You use whatever IP address hosts the Tomcat server, as far as your Apache server is concerned.
This is either a simple or complicated question depending on your environment.
It's going to be hard to go much further without examining  your setup, however we can try a couple of things:

Can I take it that your apache server and your tomcat server are in fact the same machine ?
If so, is Tomcat running ?
Is it listening on port 991 ?

netstat -aN
run on the Tomcat server, might tell you something
if tomcat is running on port 991, I would expect this to show up

as might
wget http://x.x.x.x:991/reports
(or whatever the URL is), run from the Apache server
It should return the expected page (HTML), when run from the Apache server, if you have things set up correctly.

DocumentRoot sets the directory from which httpd will serve files.
tcp        0      0 *:991                     *:*                         LISTEN

On same server...
OK, so it's running...

What happens with
wget http://127.0.0.1:991/your_url   ?


Remember to check the tomcat access logs, too.
[root@messaging jasperserver]# wget http://127.0.0.1:991/tmr.ecommunicate.biz
--2013-01-16 10:32:56--  http://127.0.0.1:991/tmr.ecommunicate.biz
Connecting to 127.0.0.1:991... connected.
HTTP request sent, awaiting response... 404 Not Found
2013-01-16 10:32:56 ERROR 404: Not Found.

[root@messaging jasperserver]#
There's nothing at that address... check that  tmr.ecommunicate.biz is correct.
Try wget http://127.0.0.1:991 also.
[root@messaging jasperserver]# wget http://127.0.0.1:991
--2013-01-16 10:44:00--  http://127.0.0.1:991/
Connecting to 127.0.0.1:991... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7777 (7.6K) [text/html]
Saving to: `index.html'

100%[===========================================================================================================================================================>] 7,777       --.-K/s   in 0s

2013-01-16 10:44:00 (436 MB/s) - `index.html' saved [7777/7777]

[root@messaging jasperserver]#
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <title></title>
    <meta http-equiv="refresh" content="0;url=home.html">
     <script language="javascript" type="text/javascript">
     window.location="home.html";
     </script>

  </head>
  <body>
  If your browser doesn't automatically go there,
you may want to go to <a href="home.html">the destination</a>
manually.

  </body>
</html>

This is index.html
I get a different index file if I use the document root above... which refers to Tomcat
You'll need to find a working URL using wget, something that returns the result you are looking for.
Once you have that, you can try it again from outside the system, hitting apache and using the redirect rules.  The aim being to make the HTTP request from the outside translate into a tomcat one that works.
Pls see and comment:
http://community.jaspersoft.com/wiki/connecting-apache-web-server-tomcat-and-writing-re-direct-rules

What do you suggest please as I'm new to this....
Well... I would suggest doing what they suggest.  They are using mod_jk.

The problem remains though, what's the URL for jasper reports ?  Could it be  /jasperserver-pro ?
Does this help?
Configure which URLs to manage with Apache

At this point, you'll need to configure Apache to tell it which URLs to process and hand off to Tomcat, and which URLs you want Apache itself to process. For both cases, you'll need to modify /etc/apache2/sites-enabled/000-default. You can add entries right below the "DocumentRoot" line, within the VirtualHost settings. Add the following line under the DocumentRoot entry. This makes it so that you can request JRS via the Apache web server.

JkMount /jasperserver-pro* worker1

Save the file, and restart the apache service (/etc/init.d/apache2 restart). If you now go to http://localhost/jasperserver-pro, you should see the normal JasperReports Server login screen. What you have accomplished so far is to put the Apache web server in front of Tomcat.

What is exact line to add?
If you are using mod_jk you can do exactly as they say.

If you do a
wget http://127.0.0.1:991/jasperserver-pro
and it works, then you can probably do it using mod_proxy (as you initially wanted), by using

ProxyPass  /jasperserver-pro        http://127.0.0.1:991/jasperserver-pro

If the wget works, but the the apache forward doesn't work, look in the tomcat access logs again.
Tx.
Trying with mod_proxy

But what is this instruction above as doesn't compile:
JkMount /jasperserver-pro* worker1

PS What are advantages of mod_proxy over mod_jk. Which do you prefer?
JkMount is mod_jk, so it will only work  with mod_jk.
mod_jk allows load balancing and some other clever stuff.

mod_proxy is slightly simpler than mod_jk, so if I was doing it I would start with that.


So,
ProxyPass  /jasperserver-pro        http://127.0.0.1:991/jasperserver-pro
(+ same for Reverse)
Tx! I've used full path: pls see my code - but still no joy.


#A1 Telecoms / Shaunw Code to point to Tomcat/JasperReportsServer
<VirtualHost *:80>
#  DocumentRoot /home/shaunw/jasperreports-server-cp-5.0.0
#DocumentRoot  JkMount /jasperserver-pro* worker1
  ServerName www.tmr.x
  ErrorLog logs/messaging_error_log
  CustomLog logs/messaging_access_log common
  ProxyPreserveHost On
# ProxyPass / ajp://127.0.0.1:8009/
# ProxyPass / ajp://localhost:8009/
#  ProxyPassReverse / ajp://localhost:8009/
    ProxyPass  /home/shaunw/jasperreports-server-cp-5.0.0        http://127.0.0.1:991/home/shaunw/jasperreports-server-cp-5.0.0
    ProxyPassReverse /home/shaunw/jasperreports-server-cp-5.0.0  http://127.0.0.1:991/home/shaunw/jasperreports-server-cp-5.0.0
</VirtualHost>

and

[root@messaging jasperreports-server-cp-5.0.0]# wget http://127.0.0.1:991/www.tmr.x
--2013-01-16 12:22:51--  http://127.0.0.1:991/www.tmr.x
Connecting to 127.0.0.1:991... connected.
HTTP request sent, awaiting response... 404 Not Found
2013-01-16 12:22:51 ERROR 404: Not Found.

[root@messaging jasperreports-server-cp-5.0.0]#

I can't find the log entries - pls direct me,...
other than:
[root@messaging jasperreports-server-cp-5.0.0]# cd apache-tomcat/logs/
[root@messaging logs]# ls
catalina.2013-01-13.log  catalina.out  host-manager.2013-01-13.log  localhost.2013-01-13.log  localhost.2013-01-15.log  manager.2013-01-13.log
[root@messaging logs]#

and nothing for today
First things first.
Are you sure that
 http://127.0.0.1:991/home/shaunw/jasperreports-server-cp-5.0.0
Is the correct URL ?

If it is, you should be able to do
  wget  http://127.0.0.1:991/home/shaunw/jasperreports-server-cp-5.0.0
and see the desired result (whatever that is).


If you can answer that question, we'll move on to the tomcat logs and apache.
/home/shaunw/jasperreports-server-cp-5.0.0 is installation directory.

This is results:
[root@messaging logs]# wget  http://127.0.0.1:18991/home/shaunw/jasperreports-server-cp-5.0.0
--2013-01-16 12:53:30--  http://127.0.0.1:18991/home/shaunw/jasperreports-server-cp-5.0.0
Connecting to 127.0.0.1:18991... connected.
HTTP request sent, awaiting response... 404 Not Found
2013-01-16 12:53:30 ERROR 404: Not Found.

[root@messaging logs]# wget  http://127.0.0.1:18991/
--2013-01-16 12:53:36--  http://127.0.0.1:18991/
Connecting to 127.0.0.1:18991... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7777 (7.6K) [text/html]
Saving to: `index.html'

100%[===========================================================================================================================================================>] 7,777       --.-K/s   in 0s

2013-01-16 12:53:36 (494 MB/s) - `index.html' saved [7777/7777]

[root@messaging logs]#
PS if I ssh into server and create a tunnel I can connect to JRS with
http://127.0.0.1:991/jasperserver/login.html
NB: I was hiding on EE 18991 as 991 and pls dont' be alarmed by below 18991 and not 991 port
/home/shaunw/jasperreports-server-cp-5.0.0 is installation directory.

This is results:
[root@messaging logs]# wget  http://127.0.0.1:18991/home/shaunw/jasperreports-server-cp-5.0.0
--2013-01-16 12:53:30--  http://127.0.0.1:18991/home/shaunw/jasperreports-server-cp-5.0.0
Connecting to 127.0.0.1:18991... connected.
HTTP request sent, awaiting response... 404 Not Found
2013-01-16 12:53:30 ERROR 404: Not Found.

[root@messaging logs]# wget  http://127.0.0.1:18991/
--2013-01-16 12:53:36--  http://127.0.0.1:18991/
Connecting to 127.0.0.1:18991... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7777 (7.6K) [text/html]
Saving to: `index.html'

100%[===========================================================================================================================================================>] 7,777       --.-K/s   in 0s

2013-01-16 12:53:36 (494 MB/s) - `index.html' saved [7777/7777]

[root@messaging logs]#
OK,  then if
http://127.0.0.1:991/jasperserver/login.html

is the jasper reports login URL, then I would imagine
ProxyPass  /jasperserver       http://127.0.0.1:991/jasperserver

might do the trick
I've tried...
Afraid not yet... see attached.

We seem close...
New-Text-Document--2-.TXT
Say what can we do pls...?
Has the port number suddenly changed ??!

Anyway, from you log file it would appear that..

http://127.0.0.1:18991/jasperserver/
is the correct Jasper URL as far as apache is concerned.
This is the URL that apache sends to tomcat, and the location of jasper reports.

To be absolutely clear.  
Your browser sends requests to Apache on port 80
Apache then sends these on to Tomcat, IF the ProxyPass rule is met.
That is, the ProxyPass rule says:
"If the request URL starts with 'jasperserver', then I'm going to send it to port 18991, with the name 'jasperserver'"


I am going to guess that
www.tmr.ecommunicate.co.za
is the address of your website


So that being the case if you have
ProxyPass  /jasperserver       http://127.0.0.1:18991/jasperserver

in your Apache file then you should be able to get to Jasper reports from a browser using
http://www.tmr.ecommunicate.co.za/jasperserver/


Doing something like
wget http://127.0.0.1:18991/www.tmr.ecommunicate.co.za
from the Apache server makes no sense.
www.tmr.ecommunicate.co.za is only meaningful as a way of reaching Apache in the first place.


I'm going to leave that with you now.  Good luck !
Looking to close this Q soon - still working on this issue. Thank you for your patience.
The firewall had to be opened for the port...