nginx: Supporting $uri or $request_uri

45 views
Skip to first unread message

Jason Roelofs

unread,
Mar 24, 2016, 4:04:27 PM3/24/16
to Phusion Passenger Discussions
 I seem to have run into a situation that was explicitly changed a few years ago here: https://groups.google.com/d/msg/phusion-passenger/3fSKQbmhhcI/tQjaMD1XRp0J

Basically, I need passenger to use $request_uri, not $uri when being processed inside of location block, or I need to re-think quite a bit of what I've done so far.

Specifically:

I'm trying to build a caching layer in front of my application (static page CMS) such that nginx with Lua will serve and store cache values automatically, leaving the application free to ignore caching.

My current setup is such:

server {

  # Always check the cache for a matching file first
  location / {
    lua_need_request_body on;
    content_by_lua_file /etc/nginx/lua/redis_caching.lua;
  }

  # On a cache miss: call down to the application itself during a cache miss
  # The lua script uses ngx.location.capture("/application" .. ngx.var.request_uri) to get here
  location /application {
    internal;

    passenger_enabled       on;
    passenger_min_instances 1;
    passenger_set_header    X-Forwarded-Proto $http_x_forwarded_proto;
  }

The problem here is that my application then receives the request as "/application/...", e.g. the current location block's $uri instead of the main request's $request_uri. I am unable to use named locations (@application) due to a limitation in nginx[1]. Is there a way to explicitly pass a URI to passenger from nginx such that in my case I can say "use $request_uri this time"?

Thanks

Jason

[1] https://github.com/openresty/lua-nginx-module#ngxlocationcapture
Reply all
Reply to author
Forward
0 new messages