You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kernel freak <ke...@gmail.com> on 2015/12/07 11:26:14 UTC

Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Hello friends,

I am working on some server side changes in which I have the webapps or
website hosted by Apache server is called by the URL. So if url is
www.domain-one.com, then the specific webapp or website must be served.

I have partial success in these regards as I have already configured Apache
Tomcat to host multiple webapps, and call them based on URL. It is working.

Now on to the 2nd stage of problem, where I have hosted a CMS on Apache
server, and would like to call it with a URL, *but also keep Apache tomcat
running in parallel*, and this is the main problem I am dealing with.

This may seem like a Apache server issue, but it's both, as I want to run
Apache web-server and Apache tomcat simultaneously with Virtual hosting. I
just hope there might be people here who know both servers.

I tried mod_jk without any luck. Here are the changes I made to tomcat and
apache server.

Tomcat changes : server.xml :

<Connector port="80"
protocol="org.apache.coyote.http11.Http11NioProtocol"
compression="force" compressionMinSize="1024"
               connectionTimeout="20000"  maxPostSize="5242880"
               URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"/>


<Connector port="443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
              compressionMinSize="1024" scheme="https" secure="true"
clientAuth="false"  sslProtocol="TLS"
               keystoreFile="keystorefile" keystorePass="PASSWORD"
URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"/>



 <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"/>
        <Host name="domain-first.com" autoDeploy="true"
unpackWARs="true" appBase="tooltank_webapps">
                <Alias>www.domain-first.com</Alias>
                <Context path=""/>
        </Host>

        <Host name="domain-second.com" autoDeploy="true"
unpackWARs="true" appBase="aupair_webapps">
                <Alias>www.domain-second.com</Alias>
                <Context path=""/>


    </Host>
    <Connector port="8010" protocol="AJP/1.3" redirectPort="443"
URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"
/>



Installed mod_jk with following command :


      apt-get install libapache2-mod-jk

Created file workers.properties in /etc/apache2/


# Define 1 real worker using ajp13
 worker.list=worker
 # Set properties for worker (ajp13)
 worker.worker.type=ajp13
 worker.worker.host=localhost
 worker.worker.port=8010

Instructed jk.conf to load this file :


JkWorkersFile /etc/apache2/workers.properties


Finally edited 000-default in sites-enabled to add :


    JkMount /home/user/tomcat_directory/* worker1

Then restarted Apache2, and I got this error :


[....] Restarting web server: apache2(98)Address already in use:
make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
 failed!


I understand that Tomcat is running on 80, but how do I then configure
the servers so they can run simultaneously.

Kindly let me know..

Regards,

Akshay S.

Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by Kernel freak <ke...@gmail.com>.
Hi,

Thank you for the links, I will go through it. I have configured Apache
Tomcat to serve multiple webapps depending upon the URL, but Apache
web-server is what seems to be stopping me.

The major problem I am having is I cannot find any examples if someone has
tried to do this before. I have gone a bit further since I posted the
question in the mailing list. Can you please check out this question :

http://serverfault.com/questions/740534/apache-webserver-tomcat-runing-multiple-tomcat-webapps-and-apache-webserver

Thanks a lot. Now my only-problem is how to inform Apache2 that, don't
process this URL, just forward it. I will read it in parallel what you
gave.

Regards,
Akshay S

Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 07.12.2015 11:26, Kernel freak wrote:
> Hello friends,
>
> I am working on some server side changes in which I have the webapps or
> website hosted by Apache server is called by the URL. So if url is
> www.domain-one.com, then the specific webapp or website must be served.
>
> I have partial success in these regards as I have already configured Apache
> Tomcat to host multiple webapps, and call them based on URL. It is working.
>
> Now on to the 2nd stage of problem, where I have hosted a CMS on Apache
> server, and would like to call it with a URL, *but also keep Apache tomcat
> running in parallel*, and this is the main problem I am dealing with.
>
> This may seem like a Apache server issue, but it's both, as I want to run
> Apache web-server and Apache tomcat simultaneously with Virtual hosting. I
> just hope there might be people here who know both servers.
>
> I tried mod_jk without any luck. Here are the changes I made to tomcat and
> apache server.
>
> Tomcat changes : server.xml :
>
> <Connector port="80"
> protocol="org.apache.coyote.http11.Http11NioProtocol"
> compression="force" compressionMinSize="1024"
>                 connectionTimeout="20000"  maxPostSize="5242880"
>                 URIEncoding="utf-8"
>   compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> javascript,application/x-javascript,application/javascript"/>
>
>
> <Connector port="443"
> protocol="org.apache.coyote.http11.Http11NioProtocol"
> maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
>                compressionMinSize="1024" scheme="https" secure="true"
> clientAuth="false"  sslProtocol="TLS"
>                 keystoreFile="keystorefile" keystorePass="PASSWORD"
> URIEncoding="utf-8"
>   compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> javascript,application/x-javascript,application/javascript"/>
>
>
>
>   <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"/>
>          <Host name="domain-first.com" autoDeploy="true"
> unpackWARs="true" appBase="tooltank_webapps">
>                  <Alias>www.domain-first.com</Alias>
>                  <Context path=""/>
>          </Host>
>
>          <Host name="domain-second.com" autoDeploy="true"
> unpackWARs="true" appBase="aupair_webapps">
>                  <Alias>www.domain-second.com</Alias>
>                  <Context path=""/>
>
>
>      </Host>
>      <Connector port="8010" protocol="AJP/1.3" redirectPort="443"
> URIEncoding="utf-8"
>   compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> javascript,application/x-javascript,application/javascript"
> />
>
>
>
> Installed mod_jk with following command :
>
>
>        apt-get install libapache2-mod-jk
>
> Created file workers.properties in /etc/apache2/
>
>
> # Define 1 real worker using ajp13
>   worker.list=worker
>   # Set properties for worker (ajp13)
>   worker.worker.type=ajp13
>   worker.worker.host=localhost
>   worker.worker.port=8010
>
> Instructed jk.conf to load this file :
>
>
> JkWorkersFile /etc/apache2/workers.properties
>
>
> Finally edited 000-default in sites-enabled to add :
>
>
>      JkMount /home/user/tomcat_directory/* worker1
>
> Then restarted Apache2, and I got this error :
>
>
> [....] Restarting web server: apache2(98)Address already in use:
> make_sock: could not bind to address [::]:80
> (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
> no listening sockets available, shutting down
> Unable to open logs
> Action 'start' failed.
> The Apache error log may have more information.
>   failed!
>
>
> I understand that Tomcat is running on 80, but how do I then configure
> the servers so they can run simultaneously.
>
> Kindly let me know..
>

Hi. You may have a lot of reading to do, specially on the Apache httpd side.
It will be worth it in the end, to be able to think "globally" about the issues, and to be 
able to decide where best to do what.

1) Virtual Hosts :
   http://httpd.apache.org/docs/2.2/vhosts/  --> name-based virtual hosts
2) Proxying from Apache to Tomcat :
    http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
    http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html (an alternative to mod_jk)
    .. and mod_jk you already know
3) URL Rewriting :
    http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
    (allows you to do a lot of things, in combination with mod_proxy, but at a much finer 
level)

Also, a tip if you want to use mod_jk in combination with all the Apache-httpd modules 
above : look at an alternative way to configure proxying from httpd to Tomcat, here :
http://tomcat.apache.org/connectors-doc/reference/apache.html
section : Using SetHandler and Environment Variables
This method replaces the JkMount/JkUnMount, and fits nicely in Apache httpd's <Location> 
scheme, together with mod_rewrite, mod_proxy etc..



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by Kernel freak <ke...@gmail.com>.
Hi Chris,

I just saw your mail, although I was able to solve this problem yesterday
before leaving. This is what I did. I just waned to know, if this
configuration will also work if I am using https. Thank you.

Here is what I did :

Tomcat's server.xml :


 <Connector port="8080" proxyPort="80" redirectPort="443"
protocol="HTTP/1.1" compression="force" compressionMinSize="1024"
               connectionTimeout="20000"  maxPostSize="5242880"
               URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"/>


 <Connector port="443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compr$
              compressionMinSize="1024" scheme="https" secure="true"
clientAuth="false"  sslProtocol="TLS"
               keystoreFile="keystore.jks" keystorePass="PASSWORD"
URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"/>

  <Connector port="8010" protocol="AJP/1.3" redirectPort="80"
URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"
/>
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat">
   // Multiple webapps hosted
    </Engine>


Added this in jk.conf :


<IfModule jk_module>
        JkWorkersFile   /PATH/to/workers.properties
        JkLogFile       /var/log/apache2/mod_jk.log
        JkLogLevel      notice
        JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
        JkOptions       +ForwardURIProxy
        JkMountFile     /path/to/uriworkermap.properties
</IfModule>

workers.properties :


worker.list = worker_app1
worker.worker_app1.type = lb
worker.worker_app1.balance_workers = app1_instance1
worker.worker_app1.sticky_session = true
worker.worker_app1.sticky_session_force = false
worker.worker_app1.method = busyness

worker.app1_instance1.type = ajp13
worker.app1_instance1.host = 127.0.0.1
worker.app1_instance1.port = 8010
worker.app1_instance1.host = localhost
worker.app1_instance1.lbfactor = 1
worker.app1_instance1.socket_timeout = 40
worker.app1_instance1.socket_keepalive = true
worker.app1_instance1.reply_timeout = 30000

uriworkermap.properties :


/|/* = worker_app1;

Added this to 000-default in sites-enabled

// This is the tomcat domain.
<VirtualHost *:80>
ServerName www.domain_tomcat_webapp.de
ServerAlias domain_tomcat_webapp.de
ProxyRequests on
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

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

<Location / >
Order allow,deny
Allow from all
</Location>
</VirtualHost>



Will this config also work if the the request made is in https? Kindly
let me know. Thanks a lot. :-)







On Mon, Dec 7, 2015 at 8:55 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> Akshay,
>
> On 12/7/15 2:53 PM, Christopher Schultz wrote:
> > Akshay,
> >
> > On 12/7/15 5:26 AM, Kernel freak wrote:
> >> <Connector port="80"
> >> protocol="org.apache.coyote.http11.Http11NioProtocol"
> >> compression="force" compressionMinSize="1024"
> >>                connectionTimeout="20000"  maxPostSize="5242880"
> >>                URIEncoding="utf-8"
> >>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> >> javascript,application/x-javascript,application/javascript"/>
> >>
> >>
> >> <Connector port="443"
> >> protocol="org.apache.coyote.http11.Http11NioProtocol"
> >> maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
> >>               compressionMinSize="1024" scheme="https" secure="true"
> >> clientAuth="false"  sslProtocol="TLS"
> >>                keystoreFile="keystorefile" keystorePass="PASSWORD"
> >> URIEncoding="utf-8"
> >>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> >> javascript,application/x-javascript,application/javascript"/>
> >
> > You have configured Tomcat for ports 80 and 443. When you start httpd:
> >
> >> [....] Restarting web server: apache2(98)Address already in use:
> >> make_sock: could not bind to address [::]:80
> >> (98)Address already in use: make_sock: could not bind to address
> 0.0.0.0:80
> >> no listening sockets available, shutting down
> >> Unable to open logs
> >> Action 'start' failed.
> >> The Apache error log may have more information.
> >>  failed!
> >
> > ... you get a port conflict. You have to choose: httpd or Tomcat on port
> > 80 (and 443).
> >
> >> I understand that Tomcat is running on 80, but how do I then configure
> >> the servers so they can run simultaneously.
> >
> > It looks like you started configuring for mod_jk, but didn't really
> > finish. What you have to do is proxy *all* applications from http ->
> > Tomcat. Then remove the HTTP <Connectors> from Tomcat and rely
> > exclusively on the AJP connector(s). (You really only need one single
> > AJP connector, since it will forward TLS information across to Tomcat.)
>
> Have a look at
>
> http://people.apache.org/~schultz/ApacheCon%20NA%202015/Load-balancing%20Tomcat%20with%20mod_jk.pdf
> starting at slide 19.
>
> -chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Akshay,

On 12/7/15 2:53 PM, Christopher Schultz wrote:
> Akshay,
> 
> On 12/7/15 5:26 AM, Kernel freak wrote:
>> <Connector port="80"
>> protocol="org.apache.coyote.http11.Http11NioProtocol"
>> compression="force" compressionMinSize="1024"
>>                connectionTimeout="20000"  maxPostSize="5242880"
>>                URIEncoding="utf-8"
>>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
>> javascript,application/x-javascript,application/javascript"/>
>>
>>
>> <Connector port="443"
>> protocol="org.apache.coyote.http11.Http11NioProtocol"
>> maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
>>               compressionMinSize="1024" scheme="https" secure="true"
>> clientAuth="false"  sslProtocol="TLS"
>>                keystoreFile="keystorefile" keystorePass="PASSWORD"
>> URIEncoding="utf-8"
>>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
>> javascript,application/x-javascript,application/javascript"/>
> 
> You have configured Tomcat for ports 80 and 443. When you start httpd:
> 
>> [....] Restarting web server: apache2(98)Address already in use:
>> make_sock: could not bind to address [::]:80
>> (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
>> no listening sockets available, shutting down
>> Unable to open logs
>> Action 'start' failed.
>> The Apache error log may have more information.
>>  failed!
> 
> ... you get a port conflict. You have to choose: httpd or Tomcat on port
> 80 (and 443).
> 
>> I understand that Tomcat is running on 80, but how do I then configure
>> the servers so they can run simultaneously.
> 
> It looks like you started configuring for mod_jk, but didn't really
> finish. What you have to do is proxy *all* applications from http ->
> Tomcat. Then remove the HTTP <Connectors> from Tomcat and rely
> exclusively on the AJP connector(s). (You really only need one single
> AJP connector, since it will forward TLS information across to Tomcat.)

Have a look at
http://people.apache.org/~schultz/ApacheCon%20NA%202015/Load-balancing%20Tomcat%20with%20mod_jk.pdf
starting at slide 19.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Akshay,

On 12/7/15 5:26 AM, Kernel freak wrote:
> <Connector port="80"
> protocol="org.apache.coyote.http11.Http11NioProtocol"
> compression="force" compressionMinSize="1024"
>                connectionTimeout="20000"  maxPostSize="5242880"
>                URIEncoding="utf-8"
>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> javascript,application/x-javascript,application/javascript"/>
> 
> 
> <Connector port="443"
> protocol="org.apache.coyote.http11.Http11NioProtocol"
> maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
>               compressionMinSize="1024" scheme="https" secure="true"
> clientAuth="false"  sslProtocol="TLS"
>                keystoreFile="keystorefile" keystorePass="PASSWORD"
> URIEncoding="utf-8"
>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> javascript,application/x-javascript,application/javascript"/>

You have configured Tomcat for ports 80 and 443. When you start httpd:

> [....] Restarting web server: apache2(98)Address already in use:
> make_sock: could not bind to address [::]:80
> (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
> no listening sockets available, shutting down
> Unable to open logs
> Action 'start' failed.
> The Apache error log may have more information.
>  failed!

... you get a port conflict. You have to choose: httpd or Tomcat on port
80 (and 443).

> I understand that Tomcat is running on 80, but how do I then configure
> the servers so they can run simultaneously.

It looks like you started configuring for mod_jk, but didn't really
finish. What you have to do is proxy *all* applications from http ->
Tomcat. Then remove the HTTP <Connectors> from Tomcat and rely
exclusively on the AJP connector(s). (You really only need one single
AJP connector, since it will forward TLS information across to Tomcat.)

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by Hassan Schroeder <ha...@gmail.com>.
On Mon, Dec 7, 2015 at 7:58 AM, Kernel freak <ke...@gmail.com> wrote:
> So you don't know what mistake I am making in the configuration?

Why would I? I don't have your server log to inspect. And I haven't
used mod_jk in a very long time, so I didn't even bother looking at
your config.

Also, FYI, Apache httpd has a built-in configuration checker that you
could (and apparently should) run (hint)  :-)

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by Kernel freak <ke...@gmail.com>.
So you don't know what mistake I am making in the configuration?

On Mon, Dec 7, 2015 at 4:52 PM, Hassan Schroeder <hassan.schroeder@gmail.com
> wrote:

> On Mon, Dec 7, 2015 at 7:11 AM, Kernel freak <ke...@gmail.com>
> wrote:
>
> > More information about this error may be available in the server error
> log.
> >
> > So, what am I missing.
>
> To start, the information in the server log referenced above.
>
> Secondly, I'd strongly recommend you start out by using plain old
> mod_proxy and mod_proxy_http rather than mod_jk - less config
> required, doesn't require changing your Tomcat config other than
> picking a different port number than 80 for your connectors.
>
> Good luck,
> --
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> http://about.me/hassanschroeder
> twitter: @hassan
> Consulting Availability : Silicon Valley or remote
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by Hassan Schroeder <ha...@gmail.com>.
On Mon, Dec 7, 2015 at 7:11 AM, Kernel freak <ke...@gmail.com> wrote:

> More information about this error may be available in the server error log.
>
> So, what am I missing.

To start, the information in the server log referenced above.

Secondly, I'd strongly recommend you start out by using plain old
mod_proxy and mod_proxy_http rather than mod_jk - less config
required, doesn't require changing your Tomcat config other than
picking a different port number than 80 for your connectors.

Good luck,
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat, Apache web-server : Simultaneously running both servers and Virtual Hosting.

Posted by Kernel freak <ke...@gmail.com>.
Thank you for the changes you suggested. First problem is, not all the
webapps have Https enabled, so I have to use port-number 80. Can you
suggest me an alternative configuration. I have changed it to port 8080 and
given a proxyPort=80 as follows :

<
 <Connector port="8080" proxyPort="80"
protocol="org.apache.coyote.http11.Http11NioProtocol" compression="force"
compressionMinSize="1024"
               connectionTimeout="20000"  maxPostSize="5242880"
               URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"/> -->
  -<Connector port="443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compr$
              compressionMinSize="1024" scheme="https" secure="true"
clientAuth="false"  sslProtocol="TLS"
               keystoreFile="my-keystore.jks" keystorePass="pass"
URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"/>

  <Connector port="8010" protocol="AJP/1.3" redirectPort="80"
URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/
javascript,application/x-javascript,application/javascript"
/>

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat">
    // Multiple webapp declarations
</Engine>


My sites-enabled file looks like this :

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName www.domain-shop.com

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                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 ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


<VirtualHost *:80>
ServerName www.domain_tomcat.de
ServerAlias domain_tomcat.de
ProxyRequests off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass / ajp://localhost:8010/
ProxyPassReverse / ajp://localhost:8010/

<Location / >
Order allow,deny
Allow from all
</Location>
</VirtualHost>



workers.properties looks like :

 worker.list = worker_app1
worker.worker_app1.type = lb
worker.worker_app1.balance_workers = app1_instance1
worker.worker_app1.sticky_session = true
worker.worker_app1.sticky_session_force = false
worker.worker_app1.method = busyness

worker.app1_instance1.type = ajp13
worker.app1_instance1.host = 127.0.0.1
worker.app1_instance1.port = 8010
worker.app1_instance1.host = localhost
worker.app1_instance1.lbfactor = 1
worker.app1_instance1.socket_timeout = 40
worker.app1_instance1.socket_keepalive = true
worker.app1_instance1.reply_timeout = 30000



uriworkermap.properties looks like :


# Proxy everything to backend:
/|/* = worker_app1;


jk.conf in modules-enabled


<IfModule jk_module>
        JkWorkersFile   /etc/apache2/workrs.properties
        JkLogFile       /var/log/apache2/mod_jk.log
        JkLogLevel      notice
        JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
        JkOptions       +ForwardURIProxy
        JkMountFile     /etc/apache2/uriworkermap.properties
</IfModule>




After this, when I try to open domain_tomcat.de, I get :

The server encountered an internal error or misconfiguration and was unable
to complete your request.

Please contact the server administrator, [no address given] and inform them
of the time the error occurred, and anything you might have done that may
have caused the error.

More information about this error may be available in the server error log.



So, what am I missing. Kindly let me know. Thanks a lot. :-)





On Mon, Dec 7, 2015 at 3:48 PM, Frederik Nosi <fr...@postecom.it>
wrote:

> (Yes, it's me who replied on serverfault.com, on this one:
> http://serverfault.com/questions/740534/apache-webserver-tomcat-runing-multiple-tomcat-webapps-and-apache-webserver
> ),
> On 12/07/2015 11:26 AM, Kernel freak wrote:
>
> Hello friends,
>
> I am working on some server side changes in which I have the webapps or
> website hosted by Apache server is called by the URL. So if url iswww.domain-one.com, then the specific webapp or website must be served.
>
> I have partial success in these regards as I have already configured Apache
> Tomcat to host multiple webapps, and call them based on URL. It is working.
>
> Now on to the 2nd stage of problem, where I have hosted a CMS on Apache
> server, and would like to call it with a URL, *but also keep Apache tomcat
> running in parallel*, and this is the main problem I am dealing with.
>
> This may seem like a Apache server issue, but it's both, as I want to run
> Apache web-server and Apache tomcat simultaneously with Virtual hosting. I
> just hope there might be people here who know both servers.
>
> I tried mod_jk without any luck. Here are the changes I made to tomcat and
> apache server.
>
> Tomcat changes : server.xml :
>
> <Connector port="80"
> protocol="org.apache.coyote.http11.Http11NioProtocol"
> compression="force" compressionMinSize="1024"
>                connectionTimeout="20000"  maxPostSize="5242880"
>                URIEncoding="utf-8"
>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> javascript,application/x-javascript,application/javascript"/>
>
>
>
> You're using port 80 on your server for tomcat, that's why apache fails to
> start, because port 80 is in use,  see later.
>
>
> <Connector port="443"
> protocol="org.apache.coyote.http11.Http11NioProtocol"
> maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
>               compressionMinSize="1024" scheme="https" secure="true"
> clientAuth="false"  sslProtocol="TLS"
>                keystoreFile="keystorefile" keystorePass="PASSWORD"
> URIEncoding="utf-8"
>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> javascript,application/x-javascript,application/javascript"/>
>
>
>
>  <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"/>
>         <Host name="domain-first.com" autoDeploy="true"
> unpackWARs="true" appBase="tooltank_webapps">
>                 <Alias>www.domain-first.com</Alias>
>                 <Context path=""/>
>         </Host>
>
>         <Host name="domain-second.com" autoDeploy="true"
> unpackWARs="true" appBase="aupair_webapps">
>                 <Alias>www.domain-second.com</Alias>
>                 <Context path=""/>
>
>
>     </Host>
>     <Connector port="8010" protocol="AJP/1.3" redirectPort="443"
> URIEncoding="utf-8"
>  compressableMimeType="text/html,text/xml,text/plain,text/css,text/
> javascript,application/x-javascript,application/javascript"
> />
>
>
>
> Installed mod_jk with following command :
>
>
>       apt-get install libapache2-mod-jk
>
> Created file workers.properties in /etc/apache2/
>
>
> # Define 1 real worker using ajp13
>  worker.list=worker
>  # Set properties for worker (ajp13)
>  worker.worker.type=ajp13
>  worker.worker.host=localhost
>  worker.worker.port=8010
>
>
>
> I use a load balanced worker per application, this way you can add other
> instances of the same app when needed, example:
>
> # Define Load balancer:
>
> worker.list = worker_app1
>
> # Configure load balancer with only one worker, app1_instance1
>
> worker.worker_app1.type = lb
> worker.worker_app1.balance_workers = app1_instance1
> worker.worker_app1.sticky_session = true
> worker.worker_app1.sticky_session_force = false
> worker.worker_app1.method = busyness
>
> # Define worker:
>
> worker.app1_instance1.type = ajp13
> worker.app1_instance1.host = 127.0.0.1
> worker.app1_instance1.port = 8010
> worker.app1_instance1.host = localhost
> worker.app1_instance1.lbfactor = 1
> worker.app1_instance1.socket_timeout = 40
> worker.app1_instance1.socket_keepalive = true
> worker.app1_instance1.reply_timeout = 30000
>
>
> Instructed jk.conf to load this file :
>
>
> JkWorkersFile /etc/apache2/workers.properties
>
>
> I would use a uriworkermap.properties too, where you can specify which
> path should be reverse proxied from mod_jk, from your serverfault config
> snippet:
>
> <IfModule jk_module>
>
>   JkWorkersFile /etc/apache2/workers.properties
>   JkLogLevel INFO
>   JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
>
> </IfModule>
>
>
>
> === I would change it this way, correct paths if needed  =====
>
> <IfModule jk_module>
>         JkWorkersFile   /etc/apache2/workers.properties
>         JkLogFile       /var/log/apache2/mod_jk.log
>         JkLogLevel      notice
>         JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
>         JkOptions       +ForwardURIProxy
>         JkMountFile     /etc/apache2/uriworkermap.properties
> </IfModule>
>
> ===== then on /etc/apache2/uriworkermap.properties =======
>
> # Proxy everything to backend:
> /|/* = worker_app1;
>
>
>
> You'll have to have a virtual host per domain though.
>
>
>
> Finally edited 000-default in sites-enabled to add :
>
>
>     JkMount /home/user/tomcat_directory/* worker1
>
> Then restarted Apache2, and I got this error :
>
>
> [....] Restarting web server: apache2(98)Address already in use:
> make_sock: could not bind to address [::]:80
> (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
> no listening sockets available, shutting down
> Unable to open logs
> Action 'start' failed.
> The Apache error log may have more information.
>  failed!
>
>
> I understand that Tomcat is running on 80, but how do I then configure
> the servers so they can run simultaneously.
>
> Kindly let me know..
>
> Regards,
>
> Akshay S.
>
>
>
>