Solved

How do I run Apache HTTP server and Tomcat JSP server on the same server both on port 80

Posted on 2009-05-07
14
2,136 Views
Last Modified: 2013-12-02
I'm trying to get my webserver to work nicely.

My ideal situation would be running apache2 and tomcat on the same server on port 80, letting apache2 run html files and php files while tomcat can run servlets and jsp files.
I'm also happy if tomcat just runs on port 80 and apache2 on port 10080.

My current situation is that I've managed to get tomcat to run on port 8088 (because I already run something else on port 8080), but only on 192.168. 1. 38 (and not mydomainname.com) and apache2 on port 10080, though apache2 now returns a NOT FOUND page wherever I go, while there was a site before I changed Listen 80 to 10080 in
/etc/apache2/ports.conf.

Now from reading tutorials I've concluded I need to mess around with the following files:

/etc/apache2/httpd.conf
/etc/tomcat6/server.xml
/etc/init.d/iptables

I'm clueless on what to do and have simply messed around with all of this.
I've done my efforts to let tomcat to run on port 80 and apache on 10080, but like I said,
they both are not working fully as I inteded.

I'm also behind a router and have ports 10080 and 8088 forwarded if that makes any difference.


Thanks for the help in advance.

P.S. my webserver runs Ubuntu-server Jaunty
/etc/apache2/httpd.conf
 
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
 
ProxyPass /ROOT ajp://192.168.1.38:8088/ROOT
ProxyPassReverse /ROOT ajp://192.168.1.38:8088/ROOT
 
# <Proxy *>
#Order Deny,Allow
#Deny from all
#Allow from 192.168.0
#</Proxy>
 
/etc/tomcat6/server.xml
 
<Connector port="8088"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false"
               acceptCount="100" debug="0" connectionTimeout="20000"
               disableUploadTimeout="true" />
 
/etc/init.d/iptables
 
iptables -t nat -A PREROUTING -d 82.xx.xx.94 -p tcp --dport 80 -j REDIRECT --to-ports 8088
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p TCP --dport 8088 -m state --state NEW -j ACCEPT
 
/etc/apache2/ports.conf
 
NameVirtualHost *:80
Listen 10080
 
<IfModule mod_ssl.c>
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
Listen 443
</IfModule>

Open in new window

0
Comment
Question by:_sluimers_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 2
14 Comments
 
LVL 8

Accepted Solution

by:
russell124 earned 500 total points
ID: 24331615
Are there any config files in your /etc/apache2/sites-enabled/  ?

Ubuntu and Debian organize Apache a bit different in that they will usually leave the httpd.conf alone, and specify the directives on a per-site basis with configuration files in the /etc/apache2/sites-enabled/ directory.

To enable or disable these directives, there are a series of scripts, such as "a2ensite" that create a sym link from the config in the sites-available to the sites-enabled directory.

http://www.debian-administration.org/articles/412

Check to see if there are any conflicting configuration files in your sites-enabled directory.
0
 
LVL 8

Expert Comment

by:russell124
ID: 24331654
Just for clarification, any files you see in the "sites-enabled" directory should just be sym links to the actual file in the "sites-availible" directory.  

So if you need to modify the configuration file, modify the file in the "sites-available" directory if you want to keep everything working nice with the a2ensite and the a2dissite scripts.
0
 
LVL 1

Author Comment

by:_sluimers_
ID: 24333271
Okay, that enables me to run apache on port 10080. Thanks :).
Now all I need is for tomcat to run on port 80.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:_sluimers_
ID: 24334392
I'm now trying to combine these two tutorials, that would hopefully get apache to let jsp files and servlets be run by tomcat:
http://ubuntuforums.org/showthread.php?t=219985
http://www.csse.uwa.edu.au/~ryan/tech/tomcat.html

This setup doesn't work however. When I try to access a jsp page on var/www or mydomainname.com:10080 I get a Bad Gateway response.
/etc/apache2/sites-available/default
 
<VirtualHost *:10080>
        ServerAdmin webmaster@localhost
 
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
 
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/access.log combined
 
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
 
        JkMount /servlet/* connect_id
        JkMount /*.jsp connect_id
 
</VirtualHost>
 
/etc/apache2/mods-enabled/jk.load
 
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
 
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
 
/etc/apache2/worker.properties
 
workers.tomcat_home=/usr/share/tomcat6
workers.java_home=/usr/lib/jvm/java-6-openjdk
ps=/
worker.list=ajp12, ajp13, connect_id
worker.connect_id.port=8112
worker.connect_id.host=mydomainname.com
worker.connect_id.type=ajp13
worker.connect_id.lbfactor=1
 
/etc/tomcat6/server.xml
 
......
<Connector port="8088"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false"
               acceptCount="100" debug="0" connectionTimeout="20000"
               disableUploadTimeout="true" />
......  
 <Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
               port="8112" minProcessors="3" maxProcessors="10"
               acceptCount="10" debug="0"/>
......  
 </Host>
      <Host name="catnipika.com" debug="0" unpackWARs="true">
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="virtual_log." suffix=".txt" timestamp="true"/>
        <Context path="" docBase="/var/www" debug="0" reloadable="true"/>
        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="virtual_log." suffix=".txt"
                 pattern="common"/>
        </Host>
......

Open in new window

0
 

Expert Comment

by:cfli1688
ID: 24338055
what is your Listen port?  Also, after changes to the httpd.conf, always run the apachectl configtest to check your syntax
0
 
LVL 1

Author Comment

by:_sluimers_
ID: 24338501
10080
Syntax OK
0
 
LVL 8

Expert Comment

by:russell124
ID: 24339072
Is your tomcat running properly?  Can you browse your sites on 8088?

Try making the worker.connect_id.port number match the port that Tomcat is running under.

Right now, your tomcat is running on port 8088, but your worker.connect is set to use 8112.  

0
 
LVL 1

Author Comment

by:_sluimers_
ID: 24343325
It runs fine on port 8088. I changed all the 8112's to 8088. Still bad gateway.
I tried to following the tutorial at http://ubuntuforums.org/showthread.php?t=219985I completely now, replacing 8009 with 8088 of course and commenting out the stuff from the other tutorial, but still get 403 errors when loading jsp files.
0
 
LVL 8

Expert Comment

by:russell124
ID: 24345617
What is the exact 403 error message you are getting?
0
 

Expert Comment

by:cfli1688
ID: 24350431
can you try to access a basic html page?  Does it give you error/
0
 
LVL 1

Author Comment

by:_sluimers_
ID: 24352458
Yes

Forbidden
You don't have permission to access /jsp-examples/index.jsp on this server.
/etc/apache2/sites-available/default
 
<VirtualHost *:10080>
	ServerAdmin webmaster@localhost
 
	DocumentRoot /var/www
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>
 
	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	<Directory "/usr/lib/cgi-bin">
		AllowOverride None
		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
		Order allow,deny
		Allow from all
	</Directory>
 
	ErrorLog /var/log/apache2/error.log
 
	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn
 
	CustomLog /var/log/apache2/access.log combined
 
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
 
#	JkMount /servlet/* connect_id
#	JkMount /*.jsp connect_id
 
</VirtualHost>
 
/etc/apache2/mods-available/jk.load
 
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
 
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkShmFile /var/log/apache2/jk-runtime-status
JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
 
JkMount /jsp-examples worker1
JkMount /jsp-examples/* worker1
 
JkMount /servlets-examples worker1
JkMount /servlets-examples/* worker1
 
workers.tomcat_home=/usr/share/tomcat6
workers.java_home=/usr/lib/jvm/java-6-openjdk
ps=/
worker.list=ajp12, ajp13, worker1
#worker.connect_id.port=8088
#worker.connect_id.host=catnipika.com
#worker.connect_id.type=ajp13
#worker.connect_id.lbfactor=1
 
worker.worker1.port=8088
worker.worker1.host=127.0.0.1
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
 
/etc/apache2/httpd.conf
# this place is empty
 
/etc/apache2/ports.conf
 
NameVirtualHost *:10080
Listen 10080
 
<IfModule mod_ssl.c>
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
Listen 443
</IfModule>
 
/etc/tomcat6/server.xml
 
....
<!-- Define an AJP 1.3 Connector on port 8009 -->
 
 
<Connector port="8088" protocol="AJP/1.3" redirectPort="8443" />
....
<Host name="catnipika.com" debug="0" unpackWARs="true">
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="virtual_log." suffix=".txt" timestamp="true"/>
        <Context path="" docBase="/var/www" debug="0" reloadable="true"/>
        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="virtual_log." suffix=".txt"
                 pattern="common"/>
        </Host>
....

Open in new window

0
 
LVL 1

Author Comment

by:_sluimers_
ID: 24355723
Yay! \o/ I've completely changed configuration again.
Tomcat now works on port 80!!!

I still need to know how get it to mydomainname.com
/etc/apache2/mods-available/ajp.load (made a link to it in mods-enabled)
 
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_balancer_module /usr/lib/apache2/modules/mod_proxy_balancer.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_ajp_module  /usr/lib/apache2/modules/mod_proxy_ajp.so
 
/etc/tomcat6/server.xml
 <Connector port="8009" enableLookups="false" protocol="AJP/1.3" redirectPort="8443" />
 
/etc/apache2/sites-available/default
<VirtualHost *:80>
        ServerName localhost
        ServerAdmin webmaster@localhost
 
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
 
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/ajp.error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/ajp.log combined
 
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
 
     <Proxy *>
        AddDefaultCharset Off
        Order Deny,Allow
        Allow from all
     </Proxy>
 
        ProxyPass / ajp://localhost:8009/
        ProxyPassReverse / ajp://localhost:8009/
 
</VirtualHost>
 
/etc/tomcat6/ports.conf
 
NameVirtualHost *:80
Listen 80
 
<IfModule mod_ssl.c>
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
Listen 443
</IfModule>

Open in new window

0
 
LVL 1

Author Closing Comment

by:_sluimers_
ID: 31579168
Thanks, I don't think I could have solved it without knowing about the config files in sites-enabled.
0
 
LVL 1

Author Comment

by:_sluimers_
ID: 24356188
Solved by port forwarding port 80 and 8009.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question