I'm using nginx with Rails' page caching to serve static files. In order to take advantage of static files plus being able to serve dynamic content, I'm using SSI to make nginx pull dynamic "partials" out of Rails and put them in the cached pages.
I want to use memcached to store Rails' authenticity_token, and then make nginx put it in static pages through the use of the session and nginx' memcache module.
Say /ssi/csrf_token returns the token for the current session, and it will also store the value in memcached using the key /ssi/csrf_token?session_id=41ded65....
Rails will send a cookie header like so:
Cookie: _myapp_session=41ded65...;other_cookies...
I need to let the HttpMemcachedModule retrieve the value for key /ssi/csrf_token?session_id=..., so I have to rewrite the URI /ssi/csrf_token to include the session id from the cookie. How would I go about this?
Let me try to explain this with an example so hopefully it's a bit more clear.
Say the static HTML page has the following code:
<meta name="csrf-token" content="<!--# include virtual="/ssi/csrf_token" -->"/>
So I guess the only thing I need is a rewrite rule that will turn /ssi/csrf_token into /ssi/csrf_token?session_id=41ded65..., so the memcached module will try to retrieve the proper key, and if it's not found it will go to Rails to get it.
I hope this isn't too contrived :)
rewrite /ssi/csrf_token$ /ssi/csrf_token?session_id=$cookie__my_app_sessionbut it doesn't work (from wiki.nginx.org/HttpCoreModule#.24cookie_COOKIE) – Ivan Jun 26 '11 at 1:11$cookie__MY_APP_SESSIONand it works! Now I only need to configure the memcached module. – Ivan Jun 26 '11 at 1:14echoSSI command (with $cookie_CSRF_TOKEN for example) instead ofinclude. – Ivan Jun 26 '11 at 1:16