Solved

Tomcat / apache port forwarding... CentOs server

Posted on 2013-01-14
35
1,410 Views
Last Modified: 2013-07-24
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.
0
Comment
Question by:shaunwingin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 22
  • 12
35 Comments
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38777250
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
0
 

Author Comment

by:shaunwingin
ID: 38777267
Pls see my qu:
"don't wish to open an additional port"
0
 

Author Comment

by:shaunwingin
ID: 38777269
PS pls explain function of tomcat versus apache.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 4

Accepted Solution

by:
tvedtem earned 500 total points
ID: 38777983
You are basically along the right lines.

You keep apache listening on port 80 (only) - this is the standard for HTTP and it would be unusual to do something different.

Tomcat sits behind apache, and usually for security reasons it would be configured to be unreachable by anything other than the apache server (plus whatever else you might have in your environment).  Commonly, you'd place a firewall in between the two.
Put another way,  your Tomcat server should only field requests from your Apache server, not directly from the internet.

So, to your question:
You configure apache to do different things, based upon the URL.
There are quite a few different ways you could do it.

Assuming the first bit of the URL will be the same (www.mysite.com)
Then...
Using mod_jk you configure www.mysite.com/reports to go to your tomcat server port 1234.  You might also configure other www.mysite.com requests to go elsewhere.

Go here:
http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html
to find out how.
In particular look at "Assigning URLs to Tomcat"

If for any reason you don't have mod_jk and don't want to install it, then have a look at mod_proxy instead.
0
 

Author Comment

by:shaunwingin
ID: 38779736
Tx TVEDTEM!

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

With:   ProxyPass and   ProxyPassReverse ?
0
 

Author Comment

by:shaunwingin
ID: 38780223
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/
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38781099
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.
0
 

Author Comment

by:shaunwingin
ID: 38781598
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/
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38781610
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.
0
 

Author Comment

by:shaunwingin
ID: 38781681
tcp        0      0 *:991                     *:*                         LISTEN

On same server...
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38781701
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.
0
 

Author Comment

by:shaunwingin
ID: 38781713
[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]#
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38781729
There's nothing at that address... check that  tmr.ecommunicate.biz is correct.
Try wget http://127.0.0.1:991 also.
0
 

Author Comment

by:shaunwingin
ID: 38781734
[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]#
0
 

Author Comment

by:shaunwingin
ID: 38781736
<!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
0
 

Author Comment

by:shaunwingin
ID: 38781741
I get a different index file if I use the document root above... which refers to Tomcat
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38781768
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.
0
 

Author Comment

by:shaunwingin
ID: 38781788
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....
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38781794
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 ?
0
 

Author Comment

by:shaunwingin
ID: 38781817
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?
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38781835
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.
0
 

Author Comment

by:shaunwingin
ID: 38781863
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?
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38781901
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)
0
 

Author Comment

by:shaunwingin
ID: 38782057
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,...
0
 

Author Comment

by:shaunwingin
ID: 38782060
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
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38782069
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.
0
 

Author Comment

by:shaunwingin
ID: 38782109
/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]#
0
 

Author Comment

by:shaunwingin
ID: 38782111
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
0
 

Author Comment

by:shaunwingin
ID: 38782115
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]#
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38782120
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
0
 

Author Comment

by:shaunwingin
ID: 38782492
I've tried...
Afraid not yet... see attached.

We seem close...
New-Text-Document--2-.TXT
0
 

Author Comment

by:shaunwingin
ID: 38784065
Say what can we do pls...?
0
 
LVL 4

Expert Comment

by:tvedtem
ID: 38785312
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 !
0
 

Author Comment

by:shaunwingin
ID: 39306575
Looking to close this Q soon - still working on this issue. Thank you for your patience.
0
 

Author Closing Comment

by:shaunwingin
ID: 39350587
The firewall had to be opened for the port...
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question