I need your help with an application that use as technology stack :
- DOCKER NGINX
- DOCKER with PHP-FPM and Symfony
I would like to split the page in different parts and cache some of them because are quite slow to be generated.
So I try to use SSI ( Server Side Inclue ) as is explaned in the documentation : https://symfony.com/doc/current/http_cache/ssi.html
This is the configuration of my dockers :
NGINX :
FROM nginx:1.19.2
COPY docker-compose/nginx /
ADD docker-compose/nginx/nginx.conf /etc/nginx/nginx.conf
ADD docker-compose/nginx/symfony.dev.conf /etc/nginx/conf.d/default.conf
and the configuration files :
nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens on;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log on;
error_log on;
access_log /dev/stdout;
error_log /dev/stdout;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
open_file_cache max=300;
client_body_temp_path /tmp 1 2;
client_body_buffer_size 256k;
client_body_in_file_only off;
}
symfony.dev.conf
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=default:10m;
server {
listen 80;
root /var/www/html/symfony/public;
client_max_body_size 40M;
location = /health {
return 200 "healthy\n";
}
location = /ping {
return 200 "pong\n";
}
location / {
ssi on;
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
ssi on;
fastcgi_pass php-fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_read_timeout 300;
internal;
}
location ~ \.php$ {
return 404;
}
location /status {
access_log off;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm:9000;
fastcgi_index status.html;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
As you can see I enable the SSI on the webserver.
Moreover I add this in the configuration of the framework (like doc) :
framework:
ssi: { enabled: true }
fragments: { path: /_fragment }
In the template / controller I follow the doc :
template
{{ render_ssi(controller('App\\Controller\\Pages\\HomeController::xxxx')) }}
controller
public function xxxx() {
sleep(2);
$response = $this->render('pages/home/xxxx.html.twig', [
]);
$response->setSharedMaxAge(Constants::SSI_CACHE_TTL);
return $response;
}
The sleep command is to test if the cache and iss is working propriety...
MORE INFOs :
I see in the vendor after reading this in the doc : render_ssi ensures that SSI directive are generated only if the request has the header requirement like Surrogate-Capability: device="SSI/1.0" (normally given by the web server). Otherwise it will embed directly the sub-response.
So I try to find in the code where is the block that decide if use SSI or not :
vendor/symfony/http-kernel/HttpCache/AbstractSurrogate.php
in this line :
/**
* {@inheritdoc}
*/
public function hasSurrogateCapability(Request $request)
{
if (null === $value = $request->headers->get('Surrogate-Capability')) {
return false;
}
return false !== strpos($value, sprintf('%s/1.0', strtoupper($this->getName())));
}
So I think my webserver doesn't send the ISS-Header (Surrogate-Capability) to my php-fpm.
I don't have any Idea on what can I change to make some test...
Thank you all if you can help me...
Regards
EDIT :
I crate a repository with the same problem exposed before, you can test it directly.