Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder PHP6's Avatar
    Join Date
    Aug 2008
    Location
    Czech Republic
    Posts
    237
    Thanks
    18
    Thanked 34 Times in 33 Posts

    Non-standard usage of nginx server for partially dynamic content

    Hello,

    As far as I know nginx could be used for passing static content to user very quickly. My case is a bit complicated. At first request the content is dynamic but on second (same) request the content is static. To say very long story short: On first request I am generating data with PHP script which is saved (cached) in local directory. On next (same) request I want ngnix to pass that content directly to user (without calling PHP script).

    I do not want to 'invent the bicycle'. There should be some logic which could solve my problem.

    Thanks in advance.

  • #2
    Regular Coder PHP6's Avatar
    Join Date
    Aug 2008
    Location
    Czech Republic
    Posts
    237
    Thanks
    18
    Thanked 34 Times in 33 Posts
    Here is the solution I found so far. As you know there is a command in mod_rewrite which checks if requested file exist. This trick is used by WordPress to process all dynamic requests.

    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    We could do something similar. When user makes request, we should calculate MD5 value of URL (within ngnix) and check if file under URL http://example.com/cache/md5_string exist. If URL does not exist then we should redirect request to PHP script (which will generate that file and store it in cache directory).

    I am not sure if we are allowed to have IF statement within ngnix configuration file so let’s simplify the logic. Once we get requests, we calculate MD5 value of URL and redirect user to that new link. This new link will be handled again by ngnix and thus we can check if file under that URL exist (this could be done for sure). If it does not exist then we pass it to PHP script.

    The only question I have: how can I generate MD5 value of URL within ngnix? Any solution which requires PHP is not acceptable.

    Guys do you have any ideas?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •