EzDevInfo.com

mod-jk interview questions

Top mod-jk frequently asked interview questions

apache to tomcat: mod_jk vs mod_proxy

What are the advantages and disadvantages of using mod_jk and mod_proxy for fronting a tomcat instance with apache?

I've been using mod_jk in production for years but I've heard that it's "the old way" of fronting tomcat. Should I consider changing? Would there be any benefits?


Source: (StackOverflow)

How do I build mod_jk on Mac OS X Mountain Lion?

I followed the instructions in BUILDING.txt in the native directory and executed

./configure --with-apxs=/usr/sbin/apxs

Here is some of the output

building connector for "apache-2.0"
checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking for C compiler default output file name... configure: error: C compiler cannot create executables
See `config.log' for more details.

Naturally, I searched StackOverflow for solutions since gcc was not in /usr/bin. So I popped open XCode and installed Command Line Tools. GCC was now in /usr/bin ... but I keep getting the same error.

Any ideas?


Source: (StackOverflow)

Advertisements

How to use mod_rewrite with Apache -> mod_jk -> tomcat setup?

Related to some of my earlier questions.

I now have a setup I quite like;

Apache httpd listening on port 80 accepting http and https connections. Several Tomcat instances running on several AJP ports.

Mod_Jk is sending different url requests to different tomcat instances;

www.mydomain.com/demo -> tomcat:8101
www.mydomain.com/test -> tomcat:8102
www.mydomain.com/     -> tomcat:8100

This is achieved with the following config in httpd.conf (or included sub files);

LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info

NameVirtualHost *:80

<VirtualHost *:80>
    JkMount /demo* demoTomcat (workers.properties not shown)
    JkMount /test* testTomcat
    JkMount /* rootTomcat
</VirtualHost>

And this all works great. I also have SSL setup and running for https connections using a similar VirtualHost tag;

<VirtualHost _default_:443>
    JkMount /demo* demoTomcat 
    JkMount /test* testTomcat
    JkMount /* rootTomcat
... SSL Stuff follows ....

What I'm now having trouble is that my SSL Cert is only for www.mydomain.com and NOT mydomain.com.

I've been advised to use the follow mod_rewrite calls;

Options +FollowSymlinks
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [PT,L]

I've placed these before before and after the mod_jk rules in the httpd.conf file. Apache was at first complaining that RewriteEngine was an invalid command, but that went away when I remembered the LoadModule command first :) Now Apache restarts just fine, the server starts and accepts requests and everything works the way it use to ... but thats just it, these mod_rewrite commands appear to have no effect?

I type http://mydomain.com into the browser and I just get my website as per normal. The url does not appear to change to http://www.mydomain.com and when I start to access the secured areas I get warnings that mydomain.com is NOT secured and is serving me a cert from some other website called www.mydomain.com (why this is an issue at all and it can't just use some logic to realise its the same site, I don't know!).

Am I placing the mod_rewrite rules in the wrong place? I've read that it should work, the rewrites should change the url to www. and then pass through to the mod_jk stuff for anything further?


Source: (StackOverflow)

"Not Modified" header followed by unexpected content body with sitemesh3 and mod-jk

In my Java / Struts2 / Tomcat application, when requesting some resources that generate a "304 Not Modified" response, the file is still being sent in the response.

This is a response example captured with Fiddler:

HTTP/1.1 304 Not Modified
Date: Thu, 26 Jun 2014 11:27:27 GMT
Server: Apache/2.2.16 (Ubuntu)
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100
Vary: Accept-Encoding

/*! jQuery v1.7.2 jquery.com | jquery.org/license */
(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9? 
a.defaultView||a.parentWindow:!1}function cu(a){if(!cj[a]){var b=c.body,d=f("
<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){ck||
[...]

This is a problem because the content of the returned file is inserted into the next requested file, ending up in corruption and weird behavior.

This only happens on resources loaded from the "/struts" path, like:

/struts/utils.js
/struts/js/base/jquery-1.10.2.min.js
/struts/js/base/jquery.ui.core.min.js?s2j=3.7.0

The "/struts" path is handled by the struts2 class

org.apache.struts2.dispatcher.DefaultStaticContentLoader

These are the relevant elements of the system:

  • Ubuntu 12.04.4 LTS (GNU/Linux 3.5.0-27-generic x86_64)
  • JVM 1.6.0_31-b31 Sun Microsystems Inc. (also tried with ibm-java-x86_64-71)
  • Apache2 2.2.22-1ubuntu1.6 with modjk
  • Apache Tomcat/6.0.35
  • Struts 2.3.16
  • Sitemesh 3.0.0

When connecting directly to tomcat I don't get any unexpected data after the Not Modified header.

The Apache Server configuration hasn't been modified much, just an alias for /contents and two modjk directives:

JkMount /* ajp13_worker
JkUnMount /contents/* ajp13_worker

There is nothing related to /struts or caching or anything exotic. ModJK configuration is the default settings.

Any suggestion?


Source: (StackOverflow)

What is the best way to install Mod_jk on linux to run apache in front of tomcat

I am using Wordpress for my blog and my main project is in java using tomcat server so I want each request coming to my server to go through apache.

For exemple if my site uses www.sample.com I would like to send the request to tomcat and if it is www.sample.com/wordpress send it to apache

Thanks


Source: (StackOverflow)

enabling SSL when Tomcat is interfaced by Apache web server using mod_jk

I have /usr/local/tomcat/webapps/cas, where my java app is running. after interfacing Tomcat and Apache web server(httpd) when I try http://192.168.0.117/cas I can see Login page, but when I try https://192.168.0.117/cas I got 404 not found from Apache web server not from Tomcat.

Not Found
The requested URL /cas was not found on this server.
Apache/2.2.3 (CentOS) Server at 192.168.0.117 Port 443


https://192.168.0.117/ that answered by Apache web server works well.

so I think the problem should solve by configuring Apache web server to forward some request to tomcat. there is some helps on internet but there isn't a step by step guideline.


Source: (StackOverflow)

What does the error message "all endpoints are disconnected" mean from mod_jk

Does anyone know the meaning of the info message "all endpoints are disconnected, detected by connect check (1), cping (0), send (0)"

This occurs with some regularity in my mod_jk log, but I can't find information about whether this is a problem, or just something to ignore.


Source: (StackOverflow)

mod_jk vs mod_cluster

Can someone please tell me the pro's and con's of mod_jk vs mod_cluster.

We are looking to do very simple load balancing.. We are going to be using sticky sessions and just need something to route new requests to a new server if one server goes down. I feel that mod_jk does this and does a good job so why do I need mod_cluster?


Source: (StackOverflow)

.htaccess not working apache-tomcat

I have a apache tomcat server integrated with mod_jk. I have created .htaccess files in the directories I want to restrict. but the problem is .htaccess is working in apache served directories but not in the directories which is served by tomcat.

Apache document root is /var/ww/html I created a test directory under it and its working fine.

But in /usr/local/src/apache-tomcat-6.0.35/webapps/examples I created a .htaccess and its not working.

What could be the reason?


Source: (StackOverflow)

How can I force a request through mod_jk down to a specific worker?

If I have mod_jk set up with several workers and a load balancer worker, is there a request parameter or something that would allow me to force a specific http request down to a specific worker. For instance if I have a worker worker1 is there something like this:

http://www.example.com?worker=worker1

Often we need to troubleshoot problems on a specific server in the cluster and being able to force the request directly to that server is essential.


Source: (StackOverflow)

Apache Http Load balancing failover with mod_jk

I am using apache http and the mod_jk for load balancing. While using sticky sessions if one of the tomcat instances dies the request is successfully redirected to the other node. If for some reason the applications dies but the tomcat is alive then the requests keep going to node which has the dead application. Any ideas how to resolve this?

Below you can fine me worker.properties file.

worker.list=myworker

worker.myworker1.port=8009
worker.myworker1.host=host1
worker.myworker1.type=ajp13
worker.myworker1.lbfactor=1

worker.myworker2.port=8009
worker.myworker2.host=host2
worker.myworker2.type=ajp13
worker.myworker2.lbfactor=1

worker.myworker.type=lb
worker.myworker.balance_workers=myworker1,myworker2
worker.myworker.sticky_session=True

Thanks!


Source: (StackOverflow)

No principal in request after Apache basic authentication (basic-auth) with mod_jk

Environment

Apache 2.2.13 connect to Tomcat 5.5 with mod_jk (ajp13). Apache requires basic-auth for "/" i.e. for all URLs it serves.

Problem

Once the request arrives at my app in Tomcat (it's a Servlet filter) request.getUserPrincipal() returns null. Apache, however, did authenticate the request. I did enter user/password in the browser's dialog.

Any ideas?


Source: (StackOverflow)

Apache + Tomcat with mod_jk - Web site hangs

I have a website with apache 1.3(SSL enabled) + mod_jk + tomcat 5.5 on Linux redhad setup. Just recently i started having a downtime problem with my web site. Once a day, i get my web site hang on port 80. But if i access directly through 8080 tomcat responses and web site works fine. Both 80 and 8080 ports are accessible but apache and tomcat connection with mod_jk is broken. Only after i restart tomcat, the things get back to normal.

I just configured apache mod_Jk to log the errors, so i will see if there will be any error on the next hang.

apache mod_js conf:

JkShmSize   1000M

apache workers conf:

worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=127.0.0.1
worker.worker1.port=8009
worker.worker1.lbfactor=1
worker.worker1.socket_keepalive=1
worker.worker1.recycle_timeout=180
worker.worker1.sticky_session=False

I checked web application error/warn logs on tomcat, i have some "out of memory" java exceptions. Can application errors cause this issue ? Can it be website overload problem or memory leak ? Currently dev/mapper/VolGroup00-LogVol00 has only 4% free space. Can it be a cause for the problem ?

I also got this log entry, it matchs the server hang time:

/var/log/messages: possible SYN flooding on port 8009. Sending cookies

Update: I just got another down, the mod_jk log gives this:

[Sun Nov 14 00:57:03 2010] [error] ajp_connection_tcp_get_message::jk_ajp_common.c (961): Can't receive the response message from tomcat, network problems or tomcat is$ [Sun Nov 14 00:57:03 2010] [error] ajp_get_reply::jk_ajp_common.c (1503): Tomcat is down or refused connection. No response has been sent to the client (yet) [Sun Nov 14 00:57:08 2010] [error] ajp_connection_tcp_get_message::jk_ajp_common.c (961): Can't receive the response message from tomcat, network problems or tomcat is$ [Sun Nov 14 00:57:08 2010] [error] ajp_get_reply::jk_ajp_common.c (1503): Tomcat is down or refused connection. No response has been sent to the client (yet) [Sun Nov 14 00:57:12 2010] [error] ajp_connection_tcp_get_message::jk_ajp_common.c (961): Can't receive the response message from tomcat, network problems or tomcat is$ [Sun Nov 14 00:57:12 2010] [error] ajp_get_reply::jk_ajp_common.c (1503): Tomcat is down or refused connection. No response has been sent to the client (yet) [Sun Nov 14 00:57:12 2010] [error] ajp_service::jk_ajp_common.c (1758): Error connecting to tomcat. Tomcat is probably not started or is listening on the wrong port. w$ [Sun Nov 14 00:57:12 2010] worker1 mydomain.com 50.999342

Looks my website is down on 8009 port. AJP 1.3 connector serves apache mod_jk on 8009 port.

Any help or advice would be highly appreciated.

Thanks.


Source: (StackOverflow)

Session mix up - apache httpd with mod_jk, tomcat, spring security - serving data of other user

Recently we have faced a serious problem, that one user was served data of another user. This problem is almost impossible to reproduce.

We are using standard logged-users-management provided by Spring-security, and we are sure that the problem isn't in storing user in instance variable or similar concurrency stuff in our app.

We really doubt that the problem is in SpringSecurity or Tomcat itself.

Our front-server is apache httpd, connected to tomcat via ajp connector (mod_jk). We are not doing any load balancing (httpd cares just about SSL, some url rewrites and serving some php modules)

Here is our setup:

## OS
OS Name:        Linux 
OS Version:     2.6.32-5-686
Architecture:   i386

## Apache httpd
Server version: Apache/2.2.16 (Debian)
Server built:   Sep  4 2011 20:27:42

## mod_jk
mod_jk/1.2.30 (installed via apt-get)

## JVM
JVM Version:    1.6.0_18-b18
JVM Vendor:     Sun Microsystems Inc.

## Tomcat
Server version: Apache Tomcat/6.0.28
Server built:   February 12 2011 1443

We blame httpd / mod_jk from this session mix up so our only solution would be to remove apache httpd. But before we leave this popular and widely used configuration, we would like to know if anyone has faced the similar problem.

The only similar problems I have found were in load ballancing or mod_jk.

Have you ever faced some similar problem? Any hints, ideas, links or experience will be highly appreciated. Thanks!


Source: (StackOverflow)

JkMount Ignoring Alias

I am setting up a new server using Apache, Tomcat and Railo ColdFusion. I am using mod_jk to connect Apache to Tomcat, and am using a CMS system on the java server. I want to forward every request to the Tomcat server except for a specific directory of files, because of the way the CMS works.

So I setup my JkMount in my site config like the following

JkMount /* ajp13w

This works just fine, but I want to now add an ignore for a directory which is actually an Alias. I tried add this line:

Alias /store /websites/eac/www/store
JkMount !/store ajp13w

But that won't work. Is there a way to forward all files, except /store to the Tomcat server with mod_jk?


Source: (StackOverflow)