0

I have a web application running over Tomcat flawlessly, but prior to redirections and other security improvements I have to run httpd connected to tomcat.

httpd is running, but I actually don't know if it's running over Tomcat. I mean, the first thing I want to configure is a redirection, but I don't know if I'm configuring it wrong or if httpd is just not taking effect.

Rajo
  • 1
  • Run `sudo netstat -nap | grep LIST | grep :80` and you can see which one is listening on port 80. – chicks May 20 '17 at 12:52

2 Answers2

0

Only one application can bind to a specific port at a time. You can use tools like ss to determine which process is listening on your port(s) of interest.

EEAA
  • 109,363
  • 18
  • 175
  • 245
0

If you want to run Apache connected to Tomcat and the setup is ment for security improvements, we are not talking about a redirection but a Reverse Proxy.

  1. You should have the Tomcat's HTTP Connector (or AJP) listening to some other port than 80 and bind it to localhost only, e.g. you could have in your TOMCAT_HOME/conf/server.xml:

    <Connector 
        port="8080" 
        protocol="HTTP/1.1" 
        address="127.0.0.1"
        connectionTimeout="20000" 
    />
    

    If there is connector for port 80 you should remove it as you now use it on Apache. Otherwise, whichever starts first gets to bind to port 80, preventing the other. That would not be acceptable.

  2. Apache's mod_proxy needs to be installed and enabled with sudo a2enmod proxy.

  3. Add the proxy to your Apache configuration, probably inside some <VirtualHost> Directive, e.g.

    <VirtualHost *:80>
        ServerName        host.example.com
        ProxyPass         /myapp  http://localhost:8080/myapp
        ProxyPassReverse  /myapp  http://localhost:8080/myapp
    </VirtualHost>
    
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • Actually, I don't know the security reasons for installing httpd, the first need is configure redirections because of large amounts of elder absolute URLs that can't be manually changed and Apache is supposed to do the trick. Anyway that info will be useful soon but isn't about how to know if httpd is affecting Tomcat's behavior. Thanks anyway :). – Rajo Apr 25 '17 at 13:55
  • Apache doesn't take control over Tomcat by itself by just installing it. Either someone has configured it this way or you'll end up in situation where one of them doesn't work at all. As a sysadmin you should at least know your configuration, not just take a shortcut of knowing some pieces of the current state. Please check your HTTP Connector configuration from step 1. If it has port `80` it can't be working the way you desire. – Esa Jokinen Apr 25 '17 at 14:31
  • Tomcat is taking 8080 and httpd 80, but anyway it doesn't mean that both service are connected, actually the only thing I know is that they're both working, but don't know if together or separately. – Rajo Apr 26 '17 at 06:16
  • By this answer you should be able to figure it out. Read your configuration. – Esa Jokinen Apr 26 '17 at 06:22
  • It's configured to cooperate but the point is that I want to try it. I mean, I have a redirection for "my.virtual.host.ip:*" and going to "my.virtual.host.ip/redirected" redirects, but when I'm going to the page in Tomcat ("my.virtual.host.ip:8080/redirected") it isn't redirecting. So I think they're not cooperating. – Rajo Apr 26 '17 at 07:24
  • That's not the way how they co-operate. Apache, used for the redirection, answers on port `80`, doing the redirection there. Tomcat, that listens on port `8080`, has no clue what Apache is doing. It just does what it is configured to do. Therefore you should use Apache as a reverse proxy, like explained in the answer: Apache takes care of the redirection and serves pages from Tomcat trough the reverse proxy. – Esa Jokinen Apr 26 '17 at 07:43
  • Ok, it seems that definitely I had a confusion with redirecting and the proxy. Nevertheless, proxy configuration will be necesasary so fortunately it hasn't been lost time for you or for me, and you clarified some things to me. Thank you! – Rajo Apr 26 '17 at 09:53