LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-01-2010, 01:34 PM   #1
dexznrl
Member
 
Registered: Jul 2009
Posts: 36

Rep: Reputation: 0
Tomcat problem


Hello everybody,

I'm kinda new to using Tomcat so I hope for your understanding.

I have a site called "app.testsite.com"

If i put it in the webapps-folder in centos 5.5 (standard installation, no nice home-built stuff) and restart tomcat I can browse to the site if I go to http://app.testsite.com:8080.

If I put in a iptables redirect rule from 80 to 8080 I can then browse the site if i go to http://app.testsite.com. No problem so far.

If I instead of iptables rule use xinetd to redirect port 80 to 8080 I get a problem. The problem is only a part of the site loads. A bigger part yes but still not the whole site.

If I install apache (on the same server) and use it as proxy and proxy the site with this:

ProxyPass / http://localhost:8080/

The same problem as with xinetd appears.

On the other hand... If I separate (two separate machines) the apache server (app.testsite.com) and the tomcat server (app.testsite2.com) and I use the iptables rule on the tomcat server to redirect 80 to 8080.
Then I set up the proxy on the apache server like this:

ProxyPass / http://app.testsite2.com

http://app.testsite.com works like a charm

Now... I actually can live with that considering I'm going to run the servers separated from each other anyway.

BUT WHY IS THIS HAPPENING?

Seriously, I don't just want to fix it, it's driving me crazy to se a problem I don't understand.

Is there anybody here who have a clue what this could be?

Should I do something in the ProxyPass setup to make it work?

Best regards

Johan

Last edited by dexznrl; 12-01-2010 at 01:39 PM.
 
Old 12-01-2010, 03:03 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
it's happening because you are changing the HOST header at the point of proxy. From tomcat's perspective you are asking tomcat for the "localhost" website, not the "app.testsite.com" website, so it won't serve it. check this... http://httpd.apache.org/docs/current...xypreservehost
 
Old 12-01-2010, 03:16 PM   #3
dexznrl
Member
 
Registered: Jul 2009
Posts: 36

Original Poster
Rep: Reputation: 0
Firstly the tomcat server isn't set to care about http-headers.

Secondly the site loads... There are only a few things missing. The missing things aren't missed when I connect directly to the tomcat-server via port 8080 or port 80 through iptables redirect.
 
Old 12-01-2010, 03:25 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by dexznrl View Post
Firstly the tomcat server isn't set to care about http-headers.

Secondly the site loads... There are only a few things missing. The missing things aren't missed when I connect directly to the tomcat-server via port 8080 or port 80 through iptables redirect.
Yeah, when you connect with the proper hostname... No?

So what parts are missing? It's not just going to be 'some' bits. What documents are being requested but not obtained? You might want a tool like firebug on firefox to see what the browser is doing.
 
Old 12-01-2010, 03:38 PM   #5
dexznrl
Member
 
Registered: Jul 2009
Posts: 36

Original Poster
Rep: Reputation: 0
Just to be sure about it I tried with proxypreservehost on without any success.

I can connect with the IP-address directly to tomcat if i want to.
Or I can set up a new hostname in my local hostfile on my laptop and connecto to it. As long as I use port 8080 or if i make a redirect rule in iptables 80>8080 it works. It stops working only if I proxy the site.
Xinetd has sort of a transparent proxy and when I use xinetd the same problem appears.

The tomcat server only serves one site. Nothing else.

I'm gonna take a look at it with that firebug thing and see if I can see anything.

The problem is narrowed down to this: As long as I go through a iptables redirect rule 80>8080 or directly through 8080 the page works perfectly.
But if I in any way try to proxy from 80 to 8080 the problem appears.

The site is running at the moment so I actually have all the time in the world to solve it.
 
Old 12-01-2010, 03:55 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Well if it's working, why not just run tomcat on port 80 in the first place?
 
Old 12-01-2010, 04:22 PM   #7
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by dexznrl
If I install apache (on the same server) and use it as proxy and proxy the site with this:

ProxyPass / http://localhost:8080/

The same problem as with xinetd appears.
No sir. You want an AJP proxy for Tomcat. Here's an example config:
Code:
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
 
ProxyRequests Off
 
ProxyPass /foo/ ajp://localhost:8009/
Quote:
Originally Posted by acid_kewpie
... why not just run tomcat on port 80 in the first place?
That requires Tomcat to run as root. (Which OP may be OK with, but I try to avoid. )
 
Old 12-01-2010, 04:40 PM   #8
dexznrl
Member
 
Registered: Jul 2009
Posts: 36

Original Poster
Rep: Reputation: 0
Think I found the problem...

It has something to do with jnlp, whatever that is. I have no clue but I found an error in the logs that pointed me in that direction.

Anyone with any ideas about how I can find the settings-file for the jnlp so I can change it to statically connect to the proxys address?
At the moment it tries to connect to the address that the proxy connects to when it connects to the tomcat, including the port number and port 8080 isn't reachable from the outside.

Suggestions anyone?
 
Old 12-01-2010, 04:53 PM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,221
Blog Entries: 1

Rep: Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075
Hi,

For apache to work as a reverse proxy you need the following:
Code:
ProxyRequests Off
ProxyPreserveHost On

ProxyPass       /  http://localhost:8080/
ProxyPassReverse /  http://localhost:8080/
Regards

Last edited by bathory; 12-01-2010 at 05:00 PM.
 
Old 12-02-2010, 01:55 AM   #10
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
For tomcat, if you wanna use AJP, you can also use mod_jk. It might not be the best but it works. You will need to build mod_jk, Im not sure if you can find it in the CentOS repositories.

If you just wanna use HTTP, then mod_proxy should do the job. I would suggest to show use the config for apache, also test if tomcat works standalone on HTTP.
 
Old 12-03-2010, 10:14 AM   #11
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
@dexznrl: This problem is not difficult to solve if you actually pay attention to the suggestions on this thread. Instead of flailing through trial and error attempts, benefit from research and work that others have already done.
 
Old 12-03-2010, 04:58 PM   #12
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
That requires Tomcat to run as root. (Which OP may be OK with, but I try to avoid. )
Is it not possible to start as root and drop to a lesser account afterwards?
 
Old 12-08-2010, 09:03 AM   #13
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
That would be the right way to handle things, but Tomcat (last I checked) has no such ability. AFAIK, it's a single process/daemon that spawns no children - unprivileged or otherwise.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tomcat 6.0 on Linux, after modifying tomcat-users.xml still cannot login. cuian01 Linux - Newbie 1 01-28-2010 03:45 AM
fresh tomcat 5.5 install not showing tomcat homepage laggerific Linux - Software 0 10-26-2007 03:28 PM
How to make Tomcat 4.0.1 and Tomcat 5.0.28 coexist in one server? g18397 Linux - Software 0 05-16-2006 03:16 AM
Tomcat problem roger600 Linux - Software 1 10-12-2005 06:12 AM
TOMCAT init script not working on startup -- tomcat 4.x / Mandrake Linux 8.0 jmartinph Mandriva 0 03-08-2004 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration