M
M
mr-zherart2017-05-23 20:27:50
Server Side Includes
mr-zherart, 2017-05-23 20:27:50

Is it possible to use SSI with If Modified Since in Nginx?

There is a page which is cached entirely. With the help of ssi set up a "window" for the hit counter.
<!--#include virtual="ssi/page_views.php" -->
config looks like this

location ~ /ssi/page_views.php$ {
  include fastcgi_params;
  fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  if (!-f $document_root$fastcgi_script_name) {
    return 404;
  }

  ssi on;
  ssi_last_modified on;
  
  include fastcgi_params;
  fastcgi_index index.php;

  	# Backend server
  fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param QUERY_STRING    $query_string;
  fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
  fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
  
  ##
  # fastCGI Cache
  # Включаем кэширование и тщательно выбираем ключ кэша.
    ##
           
    # выше за данным примером кофига устанавливается skip_cache когда необходимо не кэшировать
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;

  fastcgi_cache wholepage;
  fastcgi_cache_valid 200 301 302 304 5m;
  fastcgi_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
}

If we leave the 'ssi_last_modified on' last modified header returned, the server returns a 304 status and ssi is down. Whether probably, that and 304 gave and dynamically the counter worked?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question