AJP Caching with NGINX

Liyaqat Mugjenkar
Tech@Travelstart
Published in
1 min readSep 12, 2017

As part of our journey in improving the user experience we have embarked on caching commonly requested resources on our NGINX layer.

Results in:
1. Increased response time to get the resource
2. Reduced load on the server serving the resource

This seems all straight forward to do, take a requested resource and use NGINX caching.

Our problem is that we use Apache JServ Protocol (AJP) to connect to our backend and using the “ajp_cache_path” causes a segmentation fault on NGINX. We could change it to use HTTP but AJP is more performant.

Solution

Receive the request in HTTP, cache the response that is forwarded to a secondary local server that uses AJP.

http {
proxy_cache_path ajp_temp/ajp_cache levels=1:2 keys_zone=ajp_cache_zone:10m inactive=24h max_size=2m;
.
.
.
server {
listen 880;
location /ajptest1/ {
proxy_pass http://127.0.0.1:880/ajptest2/;
proxy_cache ajp_cache_zone;
proxy_cache_key "$host$request_uri$cookie_user";
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating http_500;
add_header X-Cache $upstream_cache_status;
}
location /ajptest2/ {
ajp_pass tomcats/;
}

We are using a fairly new version of NGINX with AJP and this still seems to be an error that was logged in 2015.

Thanks to “itpp16” for the recommendations — https://github.com/yaoweibin/nginx_ajp_module/issues/37

--

--