You might know the situation: You’d like to run tomcat from a privileged port, but the bloody thing just won’t start. Of course, it’s java-specific. Usually, a daemon gets its port from root. Not with Java. Your possibilities are therefore somewhat cruel. let us think about the options…
- run it as root. that’s ugly and not secure, but quick & dirty and just works.
- use jsvc. this will force you to mess up the funky startup script.
- write a C programm or use iptables. The C-thing doesn’t work (for me). iptables… mmmh…
terrible, didn’t I tell you? Well… there’s another way:
use the good-old xinetd. the way is described here (search for xinetd) and the essence comes as followed.
If you want to set up Tomcat to handle port 80 requests on your system, you’ll need to add a xinetd configuration file for this purpose. Assuming xinetd is installed with the usual paths, you can do this by adding a file (as user root) to the /etc/xinetd.d directory. Listing 1 gives a sample configuration file for Tomcat.
Listing 1. xinetd redirect configuration
# Redirects any requests on port 80
# to port 8080 (where Tomcat is listening)
service tomcat
{
socket_type = stream
protocol = tcp
user = root
wait = no
port = 80
redirect = localhost 8080
disable = no
}After you’ve added the configuration file, you’ll need to restart xinetd to actually activate the redirection.
cool, eh?
I have my tomcat in /home/userName/applications/tomcat6
your code said
service tomcat
{ …
does that means “xinetd redirect configuration” will actually works automatically without knowing where tomcat is installed?
Hi John,
No. The code says «redirect = localhost 8080», so everything’s being forwarded to this host:port (here localhost:8080).
Xinetd doesn’t want to know, WHERE tomcat (or any application) is installed. Instead, it uses just host:port to communicate.
Cheers!
I followed your advice but it only works in my local computer changing tomcat -> http as follows. I still cannot access the tomcat web server from outside
(I am running fedora 12 and tomcat 7)
# Redirects any requests on port 80
# to port 8080 (where Tomcat is listening)
service http
…
Hi Renan,
have a look at
/etc/xinetd.conf. There should be a section calleddefaultscontaining a option calledonly_from = localhost. Comment this and restart the xinet daemon. It should work then. But have a look at the other services as well: Everything is open then.Cheers,
marcus