LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Override Apache tomcat behaviour (http://www.linuxquestions.org/questions/linux-server-73/override-apache-tomcat-behaviour-4175412165/)

keirvt 06-18-2012 11:09 PM

Override Apache tomcat behaviour
 
I have a Tomcat application installed in a Redhat server and it performs services for a set of users.

I have another html/cgi script that obtains informations from an SQL database resident on that server which works on another test server (without Tomcat)


How can I use the Apache server to also serve my html file alongside the installed Tomcat application. I see this being done on another port than the usual port 80.

I tried adding a directive listening on port 8081 and defining a DocumentRoot. A browser responds "Unable to connect"

I can run an independent web server such as python twisted (and others i have tried) and independently serve a static web page on port 8081.

That works for static pages but its too difficult to get the CGIs workin. It would be best to use Apache since I know it works with Apache and I don't have to reinvent a web server.

I can perhaps run an independent Apache process but before going to all that trouble I would be happier configuring the existing Apache instance to access normal web pages as well as being intercepted by Tomcat.
~

sag47 06-19-2012 12:32 AM

I'm not sure I smell what you're cooking. Basically what you want to do is to serve a servlet from Tomcat while still executing normal html+cgi using Apache (outside of Tomcat). That can totally be done and they both can be served on the same port. Apache would proxy Tomcat.

This is what the Apache JServ Protocol was invented for (among other things). You can use mod_proxy, mod_cluster, or mod_jk to accomplish connecting Apache and Tomcat together. Since you're using AJP you could remove the HTTP (port 8080) and HTTPS (port 8443) connectors from Tomcat. mod_proxy is most recommended if you're going to use AJP (mod_cluster is still relatively new and I don't have much experience with it).

*Edit* After reading more docs there appears to be a mod_proxy_ajp module.
http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html

I found that while reading http://tomcat.apache.org/tomcat-5.5-doc/config/ajp.html

Either way I still recommend that method. You'll get better performance out of it.

SAM

keirvt 06-19-2012 11:22 PM

Thanks but not what I'm after
 
Apache and Tomcat are already set up and serving an application called DSpace.
DSpace has a postgres database and I'm extracting information with another program.

I don't want to use Tomcat. I want a normal web page and and associated cgi script to run in the usual way and on a different port.

Suppose my server is called clinical.com.au
and I have a "hello World" web page.
If a browser points to httpd://clincal.com.au then it presents the Tomcat application.
If the browser points to httpd://clincal.com.au:8081 then the broser gets the "Hello World" page.

If I run a Python web server on port 8081 then I get the desired behaviour but I can't do any cgi stuff.
I I can get Apache to do this then that would be excelent.

sag47 06-19-2012 11:42 PM

What you ask is still possible.

You would have to modify httpd.conf and change the port.
  • Fedora 16: /etc/httpd/conf/httpd.conf
  • Ubuntu 12.04: /etc/apache2/ports.conf

Depends on your OS as to where it is located but you basically need to change the following value.
Code:

Listen 80
Set 80 to 8081

SAM

keirvt 06-21-2012 07:21 PM

Thanks but not going to work
 
You can't just change the port because that will disable the Tomcat application listening on port 80. The idea is that a browser going to port 80 gets the Tomcat app and a browser going to 8081 get my fabulous web pages.

I think I solved it by installing a complete separate instance of Apache.
Very clear istruction on how to do this are at

http://mail-archives.apache.org/mod_...l.yahoo.com%3E

This allows a completely different set of configurations and web page directories. You can also run the second sever as a different user than apache and keep everthing nice and separate from the other server. I installed and it serves the web page on port 8081 will Tomcat is seen on 80.

I am held up getting the cgi to work as is sometimes the way with initial Apache configs. I suddenly got all these other jobs to get done so this project is parked for a few days. However I am sure it will work.

Anyway thanks for your suggestions.

sag47 06-21-2012 10:56 PM

Quote:

Originally Posted by keirvt (Post 4708912)
You can't just change the port because that will disable the Tomcat application listening on port 80. The idea is that a browser going to port 80 gets the Tomcat app and a browser going to 8081 get my fabulous web pages.

I think I solved it by installing a complete separate instance of Apache.
Very clear istruction on how to do this are at

http://mail-archives.apache.org/mod_...l.yahoo.com%3E

This allows a completely different set of configurations and web page directories. You can also run the second sever as a different user than apache and keep everthing nice and separate from the other server. I installed and it serves the web page on port 8081 will Tomcat is seen on 80.

I am held up getting the cgi to work as is sometimes the way with initial Apache configs. I suddenly got all these other jobs to get done so this project is parked for a few days. However I am sure it will work.

Anyway thanks for your suggestions.

You're not being clear about your set up. I gave you a solution which has Apache httpd running on a different port other than 80 (given you have tomcat running on 80 already). You did not state that you're using Apache httpd as a front end for Tomcat already (httpd ProxyPass) so given lack of details there's no way I would have known.

You can have Apache httpd listen on multiple ports for different purposes using VirtualHosts. You don't need a second installation of Apache httpd, that would not be smart and resource intensive. The peg can fit in the hole with tweaking, no need to force it with several httpd instances (analogy).

I had recently specified VirtualHosts for someone so you can check out the sample configs or look it up in Apache docs. Change the port numbers respectively.

keirvt 06-21-2012 11:25 PM

First Posting
 
I tried a virtual host running on a different port and got a
"browser could not connect error". I mentioned this in my first post. Sorry if it wasn't clearer.

I was unaware that Tomcat could run without Apache which ay be the source of confusion.


There may be some configuration that allows both TOmcat and Apache (normal operation to work but after a lot of effort nothing has worked for me and that is why I posted.

A separate apache installation was a bit of work doing the install but less than figuring out a virtual host/whatever combination.....and hey! It works!

In my instance I don't think the extraa httpd processes will impact our performance.

sag47 06-22-2012 01:38 AM

Quote:

Originally Posted by keirvt (Post 4709005)
I was unaware that Tomcat could run without Apache which ay be the source of confusion.

Cool, glad your solution worked. Since tomcat runs on 8080 by default you could easily write a PREROUTING rule in iptables like so,
Code:

*nat
#Tomcat redirect
-A PREROUTING -d x.x.x.x -p tcp -m tcp --dport 80 -j DNAT --to x.x.x.x:8080
COMMIT

*filter
...
***SNIP OUT A BUNCH OF RULES***
...

-A INPUT -p tcp -m tcp -s x.x.0.0/16 -m state --state NEW --dport 8080 -j ACCEPT

Where x.x.x.x is some arbitrary IP with a subnet mask of 255.255.0.0 (hence the -s x.x.0.0/16) assuming a strict firewall. That's one way you could accomplish running just Tomcat. The same could be done for 8443 -> 443 though in this case you'll have to set up a keystore for SSL rather than relying on Apache httpd to handle certs (see conf/server.xml for an example).

The only draw back to doing that is you don't have any load balancing and redundancy (i.e. single httpd with multiple Tomcat instances to share the workload). If you're not using Apache like that then there's no reason to worry because Tomcat fully supports HTTP/1.1.


All times are GMT -5. The time now is 08:29 PM.