1

I was thinking of writing some logics to my application so that it can write the static page content to s3 or some CDN and serve primarily from there. But am not sure if this is possible.

For example is I have site.com/something, its should look for this in the cdn first and if not present serve from the varnish cache or nginx / php-fpm. The idea is to take traffic away from the server.

Is this a possible scenario?

In drupal I have seen a module that does this. It stores static file cache in disk and serve if its there. Below is a diagram they provide.

Drupal Boos Module Diagram

They ask the below addition to .htaccess

# RewriteBase /

### BOOST START ###

# Allow for alt paths to be set via htaccess rules; allows for cached variants (future mobile support)   
RewriteRule .* - [E=boostpath:normal]

# Caching for anonymous users   # Skip boost IF not get request OR uri has wrong dir OR cookie is set OR request came from this server OR https request   
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [OR]   
RewriteCond %{REQUEST_URI} (^/(admin|cache|misc|modules|sites|system|openid|themes|node/add|comment/reply))|(/(edit|user|user/(login|password|register))$) [OR]   
RewriteCond %{HTTPS} on [OR]   
RewriteCond %{HTTP_COOKIE} DRUPAL_UID [OR]   
RewriteCond %{ENV:REDIRECT_STATUS} 200   
RewriteRule .* - [S=3]

# GZIP   
RewriteCond %{HTTP:Accept-encoding} !gzip   
RewriteRule .* - [S=1]   
RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html\.gz -s   
RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html\.gz [L,T=text/html,E=no-gzip:1]

# NORMAL   
RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html -s   
RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]

### BOOST END ###

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

I don't exactly get what this is, but fairly understand that the user have to hit apache for this. Can there be a better solution? I might be thinking really foolish here, but want to explore the possibilities.

Safwan Erooth
  • 273
  • 1
  • 6

0 Answers0