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,117 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_
  • 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
A short film showing how OnPage and Connectwise integration works.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now