6

This link explains how to create static files from dynamic content using Nginx.

My question is this: can I achieve the same if login sessions are involved. ie. when I want to serve content to only registered users and not otherwise. So how to overcome sessions when it comes to caching and finally to use the cache next time for another session?

Detailed scenario:

The goal of my website is to serve content to only registered users.

There are plenty of users logged in, each having different session IDs.

A php page queries the DB and finds "XYZ" that user "A" wants and generates HTML output.

Now if user "B" (with a different session ID) after sometime wants the same "XYZ", how to make Nginx to deliver from cache without making the php page to query the db again.

Has anybody done this before?


Clarification regarding possible question dupes:

nginx caching dynamic content to static My question is caching dynamic content when sessions are involved. The above question is more general (no mention about sessions).

Thale
  • 193
  • 1
  • 9
  • HTTP is all around resources (URI) and headers. I cannot grasp what you mean under "XYZ" in your question, how you identify cookies, etc. -- it would be helpful if you could define your question in technical terms. – Alexander Azarov Feb 26 '12 at 13:15

2 Answers2

3

I think you'll be better off looking at Varnish for this, nginx has very limited caching functionality.

With nginx you can detect cookie data and use that to force the user a different cache key as shown here, but this probably isn't enough for what you want to do.

PJunior
  • 230
  • 2
  • 10
Kura
  • 233
  • 2
  • 7
  • 1
    Second link has broken, content is available at the Internet Archive: https://web.archive.org/web/20130317092133/https://syslog.tv/2010/04/18/new-syslog-tv-nginx-wordpress-site-configuration/ – redburn Aug 03 '14 at 09:05
0

You can use HttpSsiModule wherever you need dynamic works (Session vs.)

Mkrc
  • 1
  • 2