LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Tomcat -> Apache2 (https://www.linuxquestions.org/questions/linux-server-73/tomcat-apache2-830940/)

mathos200 09-08-2010 04:36 AM

Tomcat -> Apache2
 
I have Apache2 installed and serving up standard webpage and I have linked it to Tomcat6 running on the same server (OpenSuse 11.2). What I'd like to do is: When you type www.climacity.ch the users should be redirected to www.climacity.ch/Axis, instead it shows the default Tomcat page. The url in the address bar should remain www.climacity.ch. When I configure the Tomcat's server.xml, I get Internal Server Error. I googled a lot, but couldn't find the clue. Any ideas?

Here my configuration files:
Apache (/etc/apache2/vhost.d/climacity.conf):

JkWorkersFile /etc/tomcat6/workers.properties
JkLogFile /var/log/tomcat6/mod_jk.log
JkLogLevel error

NameVirtualHost 195.176.237.119:80

<VirtualHost www.climacity.ch:80>
ServerAdmin webmaster@climacity.ch
ServerName climacity.ch

Alias /Axis "/srv/tomcat6/webapps/Axis"
<Directory "/srv/tomcat6/webapps/Axis">
Options Indexes FollowSymLinks
allow from all
</Directory>

# The following line prohibits users from directly accessing WEB-INF
<Location "/Axis/WEB-INF/">
deny from all
</Location>

ErrorLog /var/log/apache2/climacity_ch-error.log
CustomLog /var/log/apache2/climacity.ch-access_log combined

HostnameLookups Off
UseCanonicalName Off
ServerSignature On

JkMount /Axis/* ajp13_01
</VirtualHost>

<VirtualHost www.climacity.org:80>
ServerAdmin webmaster@climacity.ch
ServerName climacity.org

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.climacity.org$
RewriteRule ^ http.//www.climacity.org/Axis%{REQUEST_URI} [L,P]
<Directory "/srv/tomcat6/webapps/Axis">
Options Indexes FollowSymLinks
allow from all
</Directory>

<Location "/Axis/WEB-INF/">
deny from all
</Location>

ErrorLog /var/log/apache2/climacity_org-error.log
CustomLog /var/log/apache2/climacity_org-access.log combined

HostnameLookups Off
UseCanonicalName Off
ServerSignature On

JkMount /Axis/* ajp13_02

</VirtualHost>

Tomcat (/etc/tomcat6/workers.properties):
...
worker.list=ajp12, ajp13_01, ajp13_02

worker.ajp13_01.port=8009
worker.ajp13_01.host=www.climacity.ch
worker.ajp13_01.type=ajp13

worker.ajp13_02.port=8009
worker.ajp13_02.host=www.climacity.org
worker.ajp13_02.type=ajp13

worker.ajp13_01.lbfactor=1
worker.ajp13_02.lbfactor=1
...

Tomcat (/etc/tomcat6/server.xml):
...
<Host name="www.climacity.ch" appBase="/Axis"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
</Host>
<Host name="www.climacity.org" appBase="/Axis"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
</Host>
...

bathory 09-08-2010 06:28 AM

Hi and welcome to LQ

There are some errors in your configuration:

You use different NameVirtualHost and VirtualHost notation. Those 2 should be the same, like:
Code:

NameVirtualHost 195.176.237.119:80

<VirtualHost 195.176.237.119:80>
ServerName climacity.ch
...
<VirtualHost 195.176.237.119:80>
ServerName climacity.org
...


Quote:

When you type www.climacity.ch the users should be redirected to www.climacity.ch/Axis
You can change the DocumentRoot for www.climacity.ch to /srv/tomcat6/webapps/Axis


Quote:

RewriteCond %{HTTP_HOST} ^www.climacity.org$
RewriteRule ^ http.//www.climacity.org/Axis%{REQUEST_URI} [L,P]
I guess you want to redirect to www.climacity.ch. Most likely this ewriteRule gives the 500 error.
Code:

RewriteRule ^ http.//www.climacity.ch/Axis%{REQUEST_URI} [L,P]
Since it's an external rewrite, the URL in the browser will change. Besides you say you want to do the redirect for the www.climacity.ch vhost.

mathos200 09-08-2010 07:46 AM

When you type www.climacity.ch the users should be redirected to www.climacity.ch/Axis
Quote:

You can change the DocumentRoot for www.climacity.ch to /srv/tomcat6/webapps/Axis
When I define the DocumentRoot, I can see the list of all the files, when I comment it out, it gives me error 403.
PS: I have two domains "www.climacity.ch" and "www.climacity.org", both point to our server.

Here is my climacity.conf:
JkWorkersFile /etc/tomcat6/workers.properties
JkLogFile /var/log/tomcat6/mod_jk.log
JkLogLevel error

NameVirtualHost 195.176.237.119:80

<VirtualHost 195.176.237.119:80>
ServerAdmin webmaster@climacity.ch
ServerName climacity.ch
## DocumentRoot /srv/tomcat6/webapps/Axis

<Directory "/srv/tomcat6/webapps/Axis">
Options Indexes FollowSymLinks
allow from all
</Directory>

<Location "/Axis/WEB-INF/">
## AllowOverride None
deny from all
</Location>

ErrorLog /var/log/apache2/climacity_ch-error.log
CustomLog /var/log/apache2/climacity.ch-access_log combined

HostnameLookups Off
UseCanonicalName Off
ServerSignature On

JkMount /Axis/* ajp13_01

</VirtualHost>

<VirtualHost 195.176.237.119:80>
ServerAdmin webmaster@climacity.ch
ServerName climacity.org
## DocumentRoot /srv/tomcat6/webapps/Axis

##Alias / "/srv/tomcat6/webapps/Axis"
## RewriteEngine on
## RewriteCond %{HTTP_HOST} ^www.climacity.org$
## RewriteRule ^ http.//www.climacity.org/Axis%{REQUEST_URI} [L,P]
<Directory "/srv/tomcat6/webapps/Axis">
Options Indexes FollowSymLinks
allow from all
</Directory>

# The following line prohibits users from directly accessing WEB-INF
<Location "/Axis/WEB-INF/">
## AllowOverride None
deny from all
</Location>

ErrorLog /var/log/apache2/climacity_org-error.log
CustomLog /var/log/apache2/climacity_org-access.log combined

HostnameLookups Off
UseCanonicalName Off
ServerSignature On

JkMount /Axis/* ajp13_02

</VirtualHost>

bathory 09-08-2010 08:42 AM

Quote:

When you type www.climacity.ch the users should be redirected to www.climacity.ch/Axis
You must define the name www.climacity.ch in the vhost:
Code:

<VirtualHost 195.176.237.119:80>
ServerAdmin webmaster@climacity.ch
ServerName climacity.ch
ServerAlias www.climacity.ch
...


Quote:

When I define the DocumentRoot, I can see the list of all the files, when I comment it out, it gives me error 403.
Don't you have an index page in the directory? If it's an index.jsp, you can add it to DirectoryIndex directive.


Quote:

PS: I have two domains "www.climacity.ch" and "www.climacity.org", both point to our server.
I can see that, but they look identical now you've commented out the rewrite stuff

mathos200 09-08-2010 10:03 AM

Now strange things happens: In my error logfile I can read:
File does not exist: /srv/tomcat6/webapps/Axis/factory.impl.gwt, referer: http://www.climacity.ch/A89E8DC0677F...B31.cache.html

There is no file named "factory.impl.gwt", that's gwt stuff managing my jsp pages. The class is named "/srv/tomcat6/webapps/Axis/WEB-INF/classes/axis/web/gwt/server".

mathos200 09-13-2010 09:35 AM

How can I make that also the requests points to the subdirectories? In the access.log I can read:
Quote:

... "POST /factory.impl.gwt HTTP/1.1" 404 1363 "http://www.climacity.ch/A89E8DC0677FE2750F9DED85771DAB31.cache.html" ...
When you type into your addressbar of your navigator: http://195.176.237.119/Axis/ everyting goes fine.

bathory 09-13-2010 12:17 PM

Hi,

I think that mod_rewrite is not suitable for your situation.
What you can do is to setup the vhost www.climacity.ch as a reverse proxy to the tomcat server running your application and ditch mod_jk.
So check if you have mod_proxy installed and use the following:
Code:

<VirtualHost 195.176.237.119:80>
ServerAdmin webmaster@climacity.ch
ServerName climacity.ch
ServerAlias www.climacity.ch

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/$ http://%{HTTP_HOST}/Axis

<Proxy *>
    Allow from all
</Proxy>
ProxyPreserveHost On
ProxyRequests Off

ProxyPass      /Axis  http://localhost:8080/Axis
ProxyPassReverse /Axis  http://localhost:8080/Axis
</VirtualHost>

If tomcat is listening on a different post, or your webapp is deployed under a different directory change the above accordingly.

Regardrs

mathos200 09-22-2010 07:50 AM

Hi,
Yes, I think mod_rewrite is not the right thing and reverse proxying neither. When I type in the address-bar www.climacity.ch it changes to www.climacity.ch/Axis/ instead of staying www.climacity.ch. Changing to www.climacity.ch/Axis/ makes some links faulty (our php pages are not threated by httpd, everything is forwarded to tomcat). May be the missconfiguration lays down in the server.xml file. I saw its log, the vhost www.climacity.ch is not responding so I uncommented it. I also saw, that nobody was listening on port 8443 (also uncommented).

Actually my configuration files looks like this:

/etc/apache2/vhosts.d/climacity.conf:
Quote:

JkWorkersFile /etc/tomcat6/workers.properties
JkLogFile /var/log/tomcat6/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkRequestLogFormat "%w %V %T"
## JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

NameVirtualHost 195.176.237.119:80

<VirtualHost 195.176.237.119:80>
ServerAdmin webmaster@climacity.ch
ServerName www.climacity.ch
#ServerAlias www.climacity.ch

DocumentRoot /srv/tomcat6/webapps/Axis

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/$ http://%{HTTP_HOST}/Axis/

<Proxy *>
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyRequests Off

ProxyPass /Axis http://localhost:8080/Axis
ProxyPassReverse /Axis http://localhost:8080/Axis

ErrorLog /var/log/apache2/climacity_ch-error.log
CustomLog /var/log/apache2/climacity_ch-access.log combined

<Directory "/srv/tomcat6/webapps/Axis">
Options Indexes FollowSymLinks
# AllowOverride None
Order allow,deny
allow from all
</Directory>

<Location "/Axis/WEB-INF/">
#AllowOverride None
deny from all
</Location>

JkMount /* ajp13_01

</VirtualHost>
...
/etc/tomcat6/workers.properties:
Quote:

...
worker.list=ajp13_01,ajp13_02
worker.ajp13_01.port=8009
worker.ajp13_01.host=localhost
worker.ajp13_01.type=ajp13

worker.ajp13_02.port=8010
worker.ajp13_02.host=localhost
worker.ajp13_02.type=ajp13

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_01,ajp13_02
...
/etc/tomcat6/server.xml:
Quote:

<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->
<!-- <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" /> -->

<Connector port="8009" protocol="AJP/1.3" />
<Connector port="8010" protocol="AJP/1.3" />

<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

</Host>

<!--
<Host name="www.climacity.ch" appBase="/srv/tomcat6/webapps/Axis"
unpackWARs="false" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="climacity_ch_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
</Host>
-->

bathory 09-22-2010 12:48 PM

Quote:

Yes, I think mod_rewrite is not the right thing and reverse proxying neither. When I type in the address-bar www.climacity.ch it changes to www.climacity.ch/Axis/ instead of staying www.climacity.ch. Changing to www.climacity.ch/Axis/ makes some links faulty (our php pages are not threated by httpd, everything is forwarded to tomcat).
Yes, if you're using also php pages, you cannot use reverse proxy to redirect everything to tomcat.

Quote:

May be the missconfiguration lays down in the server.xml file
I'm not familiar on how to deploy appliations on tomcat, but IIRC the app.xml defining the context path should be placed under /srv/tomcat6/conf/Catalina/localhost directory.

I guess you need to change the DocumentRoot to be /srv/tomcat6/webapps, if you app is deployed under /Axis, because with the rewrite the /Axis uri becomes actually /srv/tomcat6/webapps/Axis/Axis


All times are GMT -5. The time now is 11:58 PM.