Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes IDEs, Version Control and other tools and the fly likes Configuring http://localhost in Tomcat/Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Configuring http://localhost in Tomcat/Eclipse" Watch "Configuring http://localhost in Tomcat/Eclipse" New topic
Author

Configuring http://localhost in Tomcat/Eclipse

D Taylor
Greenhorn

Joined: Jun 10, 2008
Posts: 8
Hi,

If I have an application running on Tomcat 5.5 through Eclipse which allows me to see my app by connecting to http://localhost:8080/myapp/index.jsp, how can I configure the system to direct to my app automatically if the user just goes to http://localhost?

I've seen this done before and I've heard of other people talking about it, but I can't see which settings I need to alter to achieve it.

The reason I'm asking is that until yesterday all my applications were working fine by just browsing to http://localhost, but suddenly something has changed and the address no longer works. I know the server is running fine because I can go to http://localhost:8080/myapp/index.jsp and my page is still there - but as the 'redirect' isn't working and all my urls are relative, none of my includes or CSS are picking up any more. :-/

I've looked in the usual places such as web.xml and httpd.conf, but cannot think of anything I've changed in those files at all.

Many thanks!

Dave
Rodrigo Lopes
Ranch Hand

Joined: Feb 29, 2008
Posts: 119
Since you mentioned httpd.conf file, I assume that you have an Apache HTTP server.
This is responsible to answer for requests on port 80 (the default port).
When you access http://localhost, is there any answer?
If not, check if the http server is running.

If there's answer from apache, then check the integration between Apache and Tomcat.
D Taylor
Greenhorn

Joined: Jun 10, 2008
Posts: 8
I presume so, yes. How do I tell? Unfortunately this is not my system - I've been drafted in to take over it, so I'm grasping at straws.

I've rebooted my machine many times before and all it's taken to work is to load up Eclipse with my project, start the Tomcat server, and my stuff pops up at http://localhost. But since yesterday it's stopped doing that.

If I navigate to http://localhost at the moment, all I get is an HTTP 404 Not Found error. And this is the same with all my projects which used to work fine.

If I look under C:\Program Files\Apache Software Foundation then I can see two directories - Apache2.2 and Tomcat5.5, and if I look under 'Services' in Control Panel I can see 'Apache Tomcat' and 'Apache2' services.

Many thanks for your help.

Dave
Rodrigo Lopes
Ranch Hand

Joined: Feb 29, 2008
Posts: 119
Originally posted by D Taylor:
If I look under C:\Program Files\Apache Software Foundation then I can see two directories - Apache2.2 and Tomcat5.5, and if I look under 'Services' in Control Panel I can see 'Apache Tomcat' and 'Apache2' services.


Are they both running?
D Taylor
Greenhorn

Joined: Jun 10, 2008
Posts: 8
No, neither of them is. If I run the Apache Tomcat one, it starts fine. If I go to http://localhost:8080/index.jsp then it brings up the Tomcat test page fine. But nothing from http://localhost.

If I try to run the Apache2 one it gives an error saying 'Windows could not start the Apache2 on Local Computer. For more information, view the System Event log, etc..."

I've gone to C:\Program Files\Apache Software Foundation\Apache2.2\logs\error.log, but according to Windows the last time this file was modified was 5 days ago! Which is strange, because the last few errors are:

[Mon Jun 09 09:31:36 2008] [error] (OS 10061) No connection could be made because the target machine actively refused it. : proxy: HTTP: attempt to connect to 127.0.0.1:8080 (*) failed
[Mon Jun 09 09:31:41 2008] [error] (OS 10061) No connection could be made because the target machine actively refused it. : proxy: HTTP: attempt to connect to 127.0.0.1:8080 (*) failed
[Mon Jun 09 09:31:45 2008] [error] (OS 10061) No connection could be made because the target machine actively refused it. : proxy: HTTP: attempt to connect to 127.0.0.1:8080 (*) failed
[Mon Jun 09 09:39:43 2008] [error] [client 127.0.0.1] client denied by server configuration: D:/Source
[Mon Jun 09 09:40:16 2008] [error] [client 127.0.0.1] client denied by server configuration: D:/Source
[Mon Jun 09 09:44:07 2008] [error] [client 127.0.0.1] client denied by server configuration: D:/Source

:-/

Dave
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

OK, first, understand that Internet protocols come with an implied port ID. For HTTP, it's 80 and for HTTPS, it's 443. So http://localhost and http://localhost:80 are functionally identical.

Now to get a Tomcat app to respond to requests on port 80, there are 2 options:

1. If there's an Apache or other web server on the system, set it up to forward or proxy requests to the Tomcat server.

2. If there's not an Apache or other web server, reconfigure Tomcat to respond directly on Port 80. This is done by changing the "8080" in Tomcat's server.xml file and restarting Tomcat.

3. (I lied) On some systems, you can reconfigure the internal routing and firewall subsystem (Linux iptables) to redirect requests from port 80 to port 8080.

Also beware the gotcha: On a lot of OS's, ports below 1024 are protected. In order to serve on one of these ports - including ports 80 and 443, you have to be launched under a root account. Ordinary users can't open these ports for listening.

For Apache proxying, traditionally, you'd use a Tomcat connector, such as coyote. These days the recommended approach seems to be to simply use Apache's mod_proxy. I think the main difference is on the control ports. For more on linking Apache to Tomcat, check out the docs on the jakarta Tomcat website

I have used iptables port translation (solution 3), but I'm an evil person, and it was part of a convoluted process that end up in a virtual machine. Unless you're a network geek, you probably don't want to know.


Customer surveys are for companies who didn't pay proper attention to begin with.
D Taylor
Greenhorn

Joined: Jun 10, 2008
Posts: 8
OK, well I think I've made some progress with it. The fact that it was saying it had written stuff to the error logs but the time stamps on those files was not changing was setting alarm bells ringing in my head. I've just done another reboot of them system and this time when it actually started the Apache2 service all by itself. I have now got *some* content turning up when I go to http://localhost, but still not quite right. But the error logs are now being written again, so at least I'm getting somewhere.

Thing is, we had a brief power cut yesterday and I'm thinking this is responsible for knackering our servers somehow, and we're only now just getting some of the functionality back.

So I'll have another tinker with it now, and get back if I have any more problems. At least it was nothing I did wrong myself!

Many thanks!

Dave
 
GeeCON Prague 2014
 
subject: Configuring http://localhost in Tomcat/Eclipse