| Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-18-2012, 11:09 PM
|
#1
|
|
Member
Registered: Sep 2006
Location: Sydney Australia
Distribution: fedora/Ubuntu
Posts: 69
Rep:
|
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.
~
|
|
|
|
06-19-2012, 12:32 AM
|
#2
|
|
Senior Member
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,060
|
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
Last edited by sag47; 06-19-2012 at 12:38 AM.
|
|
|
|
06-19-2012, 11:22 PM
|
#3
|
|
Member
Registered: Sep 2006
Location: Sydney Australia
Distribution: fedora/Ubuntu
Posts: 69
Original Poster
Rep:
|
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.
|
|
|
|
06-19-2012, 11:42 PM
|
#4
|
|
Senior Member
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,060
|
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.
Set 80 to 8081
SAM
|
|
|
|
06-21-2012, 07:21 PM
|
#5
|
|
Member
Registered: Sep 2006
Location: Sydney Australia
Distribution: fedora/Ubuntu
Posts: 69
Original Poster
Rep:
|
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.
Last edited by keirvt; 06-21-2012 at 07:23 PM.
Reason: typos
|
|
|
|
06-21-2012, 10:56 PM
|
#6
|
|
Senior Member
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,060
|
Quote:
Originally Posted by keirvt
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.
Last edited by sag47; 06-21-2012 at 11:05 PM.
|
|
|
|
06-21-2012, 11:25 PM
|
#7
|
|
Member
Registered: Sep 2006
Location: Sydney Australia
Distribution: fedora/Ubuntu
Posts: 69
Original Poster
Rep:
|
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.
|
|
|
|
06-22-2012, 01:38 AM
|
#8
|
|
Senior Member
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,060
|
Quote:
Originally Posted by keirvt
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.
Last edited by sag47; 06-22-2012 at 01:47 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:55 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|