Enable PATH_INFO on Nginx with Lucee and Railo

Nginx logoUpdate, 2 hours after posting (11-aug-2015 15:30): I pasted an older code snippet. The correct one is underneath. (nginx: [emerg] "proxy_set_header" directive is not allowed here ...)


While setting up a new Ubuntu server, I decided to install Nginx instead of Apache httpd, having been jealous at the easy config files nginx has. I was really happy to find out Pete Freitag already created install scripts for Nginx + Lucee + Tomcat + some other goodies.

One of the first problems I encountered after install, while moving existing sites to this new server, was the absence of cgi.PATH_INFO. Especially on this blog, it is used on each page, except for the homepage.
It took me a few hours of Googling and trying, and almost gave up, since all examples on how to enable it included the use of fastcgi. Which is not what I am using: I am proxying to Tomcat.

Main problem I encountered was the fact that the PATH_INFO header was just not proxied to (or picked up at?) the Tomcat backend, even while adding "proxy_set_header PATH_INFO /bla/bla" to the config.

Lucee logoThen, it suddenly hit me. For the modcfml project, contributor Bilal Soylu added support for PATH_INFO to his AJP connector for IIS, called the BonCode connector. AJP does not natively support sending the path_info header to the AJP backend.
What Bilal did in the BonCode connector, is adding a request header xajp-path-info, which contains the actual path_info on the IIS side. He also made sure the 3 opensource CFML engines Lucee, Railo, and BlueDragon, accept this incoming header as the fallback path_info source. For example, see Lucee's cgi.path_info implementation at Github. The header is supported in Railo since May 2012, according to the JIRA ticket.

So that's cool: we can use a different header to send to Tomcat, which will still be picked up as regular path_info by Lucee/Railo/BlueDragon!

The following nugget should be placed somewhere in your nginx config:

set $pathinfo "";
# if the extension .cfm or .cfc is found, followed by a slash and optional extra
if ($uri ~ "^(.+?\.cf[mc])(/.*)") {
    # remember the filepath without path_info
    set $script $1;
    set $pathinfo $2;
    # rewrite the url to match the filepath wthout path_info
    rewrite ^.+$ $script break;
}
# set the custom path_info header
proxy_set_header XAJP-PATH-INFO $pathinfo;

After a reload of Nginx, your path_info should be working! If it isn't, let me know.

del.icio.us Digg StumbleUpon Facebook Technorati Fav reddit Google Bookmarks
| Viewed 13032 times
  1. Igal

    #1 by Igal - February 20, 2016 at 7:56 PM

    Hey Paul,

    Shouldn't it be:

    proxy_set_header X-AJP-PATH-INFO $pathinfo;

    instead of

    proxy_set_header XAJP-PATH-INFO $pathinfo;
  2. Paul Klinkenberg

    #2 by Paul Klinkenberg - February 20, 2016 at 8:21 PM

    Hi Igal, that would have been more logical, but it has always been the x without a dash. Following the boncode connector specs, where this idea came from to begin with.
    Kind regards, Paul
  3. sd

    #3 by sd - May 13, 2020 at 10:23 AM

    While setting up a new Ubuntu server, I decided to install Nginx instead of Apache httpd, having been jealous at the easy config files nginx has. I was really happy to find out Pete Freitag already created install scripts for Nginx + Lucee + Tomcat + some other goodies.
(will not be published)
Leave this field empty