routing nginx request through index file

Brian FitzGerald asked:

I would like for nginx to process: as

While loading the index.cfm file, Nginx must also pass along the “cgi path info” (/about-us) for server processing. I am very close but seeing some unexpected results.

Here is my current nginx config:

server {

    listen 80 default_server;
    server_name  _;
    index  index.cfm index.html index.htm;
    root   /var/www;
    server_name_in_redirect off;

    set $path_info $request_uri;

    try_files $uri /index.cfm$args;

    location ~* \.(cfm|cfc|cfr)$ {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header XAJP-PATH-INFO $path_info;
        proxy_connect_timeout 600;
        proxy_send_timeout 600;
        proxy_read_timeout 600;
        send_timeout 600;


This is routing to index.cfm properly if index.cfm is not supplied in the url (such as in the “about-us” example above). However, what I find odd is that explicit requests for index.cfm, such as actually prompt the user to download the file (like the server doesn’t know how to process it).

My answer:

You’re on the right track with try_files. But you want to append the complete URL path, not the query string as you had been doing. For instance:

try_files $uri /index.cfm$uri;

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.