Enabling PATH_INFO on Nginx with Lucee

96 views
Skip to first unread message

Paul Klinkenberg

unread,
Aug 11, 2015, 8:59:14 AM8/11/15
to lu...@googlegroups.com
Hi list,

Though it might seem like a shameless plug for my blog post, it is not. I figured out today how to enable cgi.path_info while using nginx and Lucee, and wanted to share it with fellow nginx users.
For some reason, path_info doesn't nativey transfer to (or picked up by?) Tomcat when proxying from nginx. I found a solution, which can be found here: http://www.lucee.nl/post.cfm/enable-path-info-on-nginx-with-lucee-and-railo

TLDR: use this config in bginx:
# 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 the custom path_info header
    proxy_set_header XAJP-PATH-INFO $2;
    # rewrite the url to match the filepath wthout path_info
    rewrite ^.+$ $script break;
}

Hope it helps anyone, kind regards,

Paul Klinkenberg

Paul Klinkenberg

unread,
Aug 11, 2015, 9:27:26 AM8/11/15
to lu...@googlegroups.com
Oops, wrong copy-paste.
Here is the right one:

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;

Kind regards,

Paul Klinkenberg

--
See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/9E24043F-7EB0-40AB-B673-D74C08817488%40ongevraagdadvies.nl.
For more options, visit https://groups.google.com/d/optout.

Igal @ Lucee.org

unread,
Aug 11, 2015, 11:12:23 AM8/11/15
to lu...@googlegroups.com
Paul,

why do you need that?  I've been using nginx for a few years now and everything seems to work well without this.  can you give a scenario where this is used?

thanks,

Igal Sapir
Lucee Core Developer
Lucee.org

Paul Klinkenberg

unread,
Aug 11, 2015, 11:45:59 AM8/11/15
to lu...@googlegroups.com
Hi Igal,

Well, using a regular proxy from nginx to tomcat 7 on ubuntu doesn't work (for me?) if you have path_info in the url, eg. /test.cfm/something
I don't seem to be the only one... https://www.google.com/search?q=path_info+nginx

Kind regards,

Paul

Igal @ Lucee.org

unread,
Aug 11, 2015, 12:07:31 PM8/11/15
to lu...@googlegroups.com
I guess you're right.

nginx has powerful URL-rewriting built in, and is rather simple to configure, so I guess I used URL-rewriting and stopped using CGI.PATH_INFO once I switched to nginx.

thanks for the info!


Igal Sapir
Lucee Core Developer
Lucee.org

Jon Clausen

unread,
Aug 11, 2015, 12:29:59 PM8/11/15
to lu...@googlegroups.com
Just curious, Paul: why not just use script_name (or path_translated, if you want the full path)?  For every environment I’m aware of, script_name returns the same info as path_info - when path_info is even available.  The only case where that might not work, that I can think of, is if you needed a symlinked path instead of the the resolved path that Tomcat uses.

Igal @ Lucee.org

unread,
Aug 11, 2015, 12:34:17 PM8/11/15
to lu...@googlegroups.com
@Jon --

PATH_INFO is not the same as SCRIPT_NAME, but it really is dependent on your configurations.  with standard config for:

     http://host/script-name.cfm/path-info

CGI.SCRIPT_NAME should return "/script-name.cfm" and CGI.PATH_INFO should return "/path-info"


Igal Sapir
Lucee Core Developer
Lucee.org

Paul Klinkenberg

unread,
Aug 11, 2015, 12:46:10 PM8/11/15
to lu...@googlegroups.com
Hi Jon, Igal,

I host a number of sites which are dependent on cgi.path_info, and changing the source code to be able to use a rewrite at the frontend isn't an option; it's not all my code.
I know doing a rewrite is the regular way to get around this problem.

We solved this same problem with mod_cfml by the way, for IIS and Apache.

Kind regards,

Paul Klinkenberg

------------


Paul Klinkenberg

unread,
Aug 11, 2015, 12:47:59 PM8/11/15
to lu...@googlegroups.com
P.s. you got me sweating there for a moment Igal... Was I wrong? Is it natively supported? 
That would've been a waste of my time. Haha!


Kind regards,

Paul Klinkenberg

------------


Igal @ Lucee.org

unread,
Aug 11, 2015, 12:51:32 PM8/11/15
to lu...@googlegroups.com
sorry 'bout that ;)


Igal Sapir
Lucee Core Developer
Lucee.org

Jon Clausen

unread,
Aug 11, 2015, 12:53:47 PM8/11/15
to lu...@googlegroups.com
Ah, sorry Igal (and Paul), you’re right.  My bad. I’ve gotten rusty on my CGI variables using frameworks to do all of that under the hood.  Ugh.
Reply all
Reply to author
Forward
0 new messages