This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Need help configuring for port 80 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Need help configuring for port 80" Watch "Need help configuring for port 80" New topic
Author

Need help configuring for port 80

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I'm running Tomcat 5.0 as a local stand-alone on Mac OS 10.4 (not XP), and I'm trying to configure Tomcat to run on port 80.

I have a test servlet running without problems at...

http://localhost:8080/scwcd01/hello-again

But when I edit Tomcat's conf/server.xml from <Connector port="8080"... to <Connector port="80"... (and restart Tomcat), I get a connection refused error with both of the following...

http://localhost/scwcd01/hello-again
http://localhost:8080/scwcd01/hello-again

I've consulted several references (including the latest edition of Sun's Core Servlets and JavaServer Pages), all of which seem to indicate that the above should work.


[ August 13, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

Are you also running Apache?

Check your tomcat logs to make sure that it's not reporting a problem attaching to port 80.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Hi Bear,

No, I'm not running Apache, and I don't see any errors in the log. Here's what I get when starting with server.xml set to port="80"...
2005-08-13 13:20:49 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: ,]http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: ,]http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: ]]http://jakarta.apache.org]]
2005-08-13 13:20:50 StandardContext[/jsp-examples]ContextListener: contextInitialized()
2005-08-13 13:20:50 StandardContext[/jsp-examples]SessionListener: contextInitialized()
2005-08-13 13:20:50 StandardContext[/servlets-examples]ContextListener: contextInitialized()
2005-08-13 13:20:50 StandardContext[/servlets-examples]SessionListener: contextInitialized()

I've read that on UNIX, ports below 1024 are "privileged," and can only be opened by root. I don't fully understand what this means, but I expect that if this were the problem, then the log would show an error, right?
[ August 13, 2005: Message edited by: marc weber ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

When I try to start Tomcat on port 80 I get the following in my catalina.out:

Aug 13, 2005 6:02:04 PM org.apache.coyote.http11.Http11Protocol init
SEVERE: Error initializing endpoint
java.net.BindException: Permission denied:80


So apparently you will need to configure tomcat to run as a priveleged user.

When I use sudo to start tomcat, everything works as expected (though usually I just let it use port 8080 and leave 80 to Apache).
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

With OSX (as with any Unix), only the root user is allowed to bind to ports < 1024. Often, this is why people run Tomcat with Apache.
Apache starts up as root, binds to the port and then downgrades itself to a user with fewer privileges.

Tomcat ships with jSvc which can be used to do something similar with Tomcat as a standalone.

Also, if you search this forum, Earnest Friedman Hill posted a link to an article that shows how to do the same thing with ipchains in Linux not too long ago. I'm guessing the same techique would work on OSX.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Ben and Bear,

Thanks for the info! I probably won't have a chance to get back to this for a few days, but I'll try starting Tomcat with sudo to verify that it's a privileged user issue. Then I'll probably try either the jSvc or start using Apache.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Well, I finally got a chance to try this (too much "real" work going on). Indeed, the XML configuration of port 80 works fine if Tomcat is started using sudo as Bear suggested, so this seems to confirm it's a privliged port issue.

Also, I want to follow up and thank Ben for his recommendation (a couple of months ago) of the text, Core Servlets and JavaServer Pages, Vol. 1, Second Edition by Marty Hall and Larry Brown. I see that a new edition of Vol. 2 is scheduled for January, 2006.

I wish I had more time to spend on this, but I'll get there eventually...
[ August 20, 2005: Message edited by: marc weber ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Here's the article that EFH shared with us a while back.
I haven't tried doing this ipchains yet but that looks like a nice solution.
http://www.klawitter.de/tomcat80.html
 
jQuery in Action, 2nd edition
 
subject: Need help configuring for port 80
 
Similar Threads
tomct realm xdb login
Internet requests to Tomcat
How Tomcat Works book - development question
Stuck on HelloWorldServlet
servlet configuration problem