0

I had failed attempts earlier at getting Nginx Fast-CGI caching to work in Nginx > Apache > PHP-FPM config so I started fresh on a new server but am still having issues.

The server has a clean Ubuntu 16.04 install with Nginx 1.14.2, Apache 2.4.18 and PHP-FPM 5.6 (just for testing sake).

My /etc/nginx/nginx.conf config is stock as I've only made changes in vhost (anything outside server block is effectively nginx.conf).

My apache2 test.mysite.com.conf is

<VirtualHost 127.0.0.1:8080>
        ServerName test.mysite.com
        DocumentRoot /var/www/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php/php5.6-fpm.sock|fcgi://localhost/var/www/
</VirtualHost>

To test caching, I have following in /var/www/cachetest.php

<?php
echo time();
?>

However testing http://test.mysite.com/cachetest.php changes every second and consequently /etc/nginx/cache is always empty (its 777 for now).

Any ideas why cache isn't working?

1

You can't fastcgi_cache because you never fastcgi_pass to PHP-FPM.

In nginx, the cache is attached to a specific method of sending requests upstream, e.g. fastcgi, proxy, uwsgi, etc.

You can either use a proxy_cache instead, or better yet, just fastcgi_pass to PHP-FPM directly from nginx, and get rid of Apache as it's redundant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.