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,106 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
Comment Utility
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
Comment Utility
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_
Comment Utility
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_
Comment Utility
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
Comment Utility
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_
Comment Utility
10080
Syntax OK
0
 
LVL 8

Expert Comment

by:russell124
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:_sluimers_
Comment Utility
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
Comment Utility
What is the exact 403 error message you are getting?
0
 

Expert Comment

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

Author Comment

by:_sluimers_
Comment Utility
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_
Comment Utility
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_
Comment Utility
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_
Comment Utility
Solved by port forwarding port 80 and 8009.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Ubuntu 14 with Apache 7 68
Best Linux Distro for this software 10 57
Change local server setting in php 6 59
Linux operating system 12 64
This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

10 Experts available now in Live!

Get 1:1 Help Now