Does Tomcat require Apache httpd?

20,664

Solution 1

Tomcat is a web server of its own, so a separate web server like Apache is not required. You probably will want to change Tomcat's port though, since it defaults to 8080 and web sites are usually on port 80.

I think people generally put Apache in front of Tomcat so they can do things like:

  • Have one website have several Tomcat instances behind it.
  • Serve static files from Apache to take load off of Tomcat.
  • Use other Apache features you may need (modules).
  • As @TacticalCoder mentions in the comments, you need to be root to listen on port 80, so some people may be using Apache as an easy way to proxy port 80 to port 8080.

I'd recommend the YAGNI approach and just go with Tomcat until/unless you find a reason you want Apache in front of it.

Solution 2

Just Tomcat. HTTPD is never a requirement for Tomcat.

Solution 3

Tomcat is a servlet container which has it's own http server ,so if you want to run a war ,you only need a tomcat ,but if you want to run a website which only include static files(html ,js ,css),you should choose apache better,even if the tomcat can do this

Share:
20,664
IAmYourFaja
Author by

IAmYourFaja

my father is a principal at burgoyne intnl and got me this job programming lisp and development. I aspire to unittesting with a concentration in mobile platforms.

Updated on August 10, 2020

Comments

  • IAmYourFaja
    IAmYourFaja almost 4 years

    If I am given a war file that contains a Java web application, and I want to run that war locally, then do I just need Tomcat, or do I need Tomcat and Apache httpd (or any other web server)? Thanks in advance!

  • IAmYourFaja
    IAmYourFaja over 12 years
    Ahhh - so Tomcat is the web server, and I'm guessing that "Catalina" is the servlet processor/container?
  • Brendan Long
    Brendan Long over 12 years
    @AdamTannon - Yeah, Catalina is the servlet container.
  • TacticalCoder
    TacticalCoder over 12 years
    @Bredan Long: "You probably will want to change Tomcat's port though" [sic]... With the caveat that, on Unx OS for example, you cannot listen on port 80/443 without being *root. But installing Java / Tomcat as root isn't necessarily a good practice: on Linux you can install Java without being root. You can also install Tomcat without being root. Then, as root, you can transparently redirect port 80/443 to 8080/4443 (for example) using the firewall (e.g. iptables). This is generally considered "more secure" than running Tomcat as root and directly listening on port 80/443.
  • IAmYourFaja
    IAmYourFaja over 12 years
    Tactical - just out of curiosity, could you explain why the port redirection is more secure than having Tomcat listening to the port directly?
  • TacticalCoder
    TacticalCoder over 12 years
    @AdamTannon: because, on Unx, you must have *root privileges to be able to listen on ports below 1024. I always prefer to both install and run software with the least privileges possible. By using a port redirection there's exactly one command that needs to be run as root: all the rest can be done from a regular user account. Sure, you could use authbind or sudo etc. but why bother: install Java + Tomcat as non-root and do a port-redirection. Details here: jvmhost.com/articles/…
  • st-h
    st-h over 10 years
    Just wanted to add this, as I have came across this shortly in a real life scenario: In case there is a security flaw in tomcat, and tomcat is run as root. Somebody might exploit this and could gain access as root to your system. You are in big trouble now. In case tomcat is run as non-root, the attacker might 'only' compromise some limited parts of your system. That can save your life one day...
  • Kanagavelu Sugumar
    Kanagavelu Sugumar over 10 years
    if HTTPD is not required for Tomcat then which process in tomcat will take care of incoming server requests? Could you please explain? Thanks.
  • TenLeftFingers
    TenLeftFingers almost 10 years
    Would it make sense to use an additional Tomcat instance then @Brendan Long: Instead of an Apache one? It makes more sense to me to use reduce variance especially if they provide the same functionality. That way the load could still be distributed but I wouldn't need to configure a separate application.
  • Brendan Long
    Brendan Long almost 10 years
    @TenLeftFingers You could try it. Apache has some advantages due to its popularity (efficiency, stability, everyone knows the configuration format), but I've never tried using Tomcat for this so I don't know how they would compare. In my personal experience, I was already running Apache when Tomcat was added to the mix.
  • sactiw
    sactiw about 9 years
    @KanagaveluSugumar Tomcat runs an default HTTP server on port 8080 (thus, set port redirection to listen requests coming to HTTP port 80 or specify port 8080 in URL requests). Also, in the supplied server.xml file, you'll see the following element: <!-- Normal HTTP --> <Connector className="org.apache.tomcat.service.PoolTcpConnector"> <Parameter name="handler" value="org.apache.tomcat.service.http.HttpConnectionHandler"‌​/> <Parameter name="port" value="8080"/> </Connector> To set Apache HTTP server in front of tomcat server, comment this entry in the server.xml.