Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-17-2012, 11:40 PM   PM User | #1
PHP6
Regular Coder

 
PHP6's Avatar
 
Join Date: Aug 2008
Location: Czech Republic
Posts: 234
Thanks: 17
Thanked 34 Times in 33 Posts
PHP6 is on a distinguished road
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.
PHP6 is offline   Reply With Quote
Old 03-18-2012, 06:22 PM   PM User | #2
PHP6
Regular Coder

 
PHP6's Avatar
 
Join Date: Aug 2008
Location: Czech Republic
Posts: 234
Thanks: 17
Thanked 34 Times in 33 Posts
PHP6 is on a distinguished road
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?

Last edited by PHP6; 03-18-2012 at 06:27 PM..
PHP6 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:36 AM.


Advertisement
Log in to turn off these ads.