Support » Plugin: WP Cloudflare Super Page Cache » How to overwrite the cache-control header on Nginx?

  • Resolved ducod

    (@ducod)


    Edit the main Nginx configuration file, usually /etc/nginx.conf, and enter these rules immediately after opening the http block:

    map $upstream_http_x_wp_cf_super_cache_active $wp_cf_super_cache_active {
    default ‘no-cache, no-store, max-age=0’;
    ‘1’ ‘s-max-age=604800, s-maxage=604800, max-age=60’;
    }

    Now open the configuration file of your domain and add the following rules inside the block that deals with the management of PHP pages:

    more_clear_headers ‘Pragma’;
    more_clear_headers ‘Expires’;
    more_clear_headers ‘Cache-Control’;
    add_header Cache-Control $wp_cf_super_cache_active;

    Save and restart Nginx.

    Thanks for your amazing cloudflare plugin and right now the site speed boost up dratically. However, I check there are two settings that require a mannually implement, for this cache-control header, I know how to do with the first paragraph, that I successfully entered into the nginx.conf file, but the second paragraph, I don’t know where should I add in.

    Thank you for your help.

    • This topic was modified 1 year, 8 months ago by ducod.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Salvatore Fresta

    (@salvatorefresta)

    Hi @ducod ,
    the second piece of rules must be added into your server block where you manage PHP, for example:

    location ~ \.php$ {
    
    here
    
    }

    When I restart nginx I get:
    2020/05/12 12:17:39 [alert] 20484#20484: *10368990 open socket #7 left in connection 290
    2020/05/12 12:17:39 [alert] 20484#20484: aborting
    2020/05/12 12:17:39 [emerg] 20564#20564: unknown directive “more_clear_headers” in /etc/nginx/sites-enabled/site.org:50

    My location ~ \.php looks like:
    location ~ \.php$ {
    more_clear_headers ‘Pragma’;
    more_clear_headers ‘Expires’;
    more_clear_headers ‘Cache-Control’;
    add_header Cache-Control $wp_cf_super_cache_active;
    include snippets/fastcgi-php.conf;
    include fastcgi_params;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME /var/www/html/site.org/public_html$fastcgi_script_name;

    Of course nginx doesn’t run with the “more_clear_headers” uncommented without throwing an error.

    Help? Grazie!

    • This reply was modified 1 year, 8 months ago by fowlerj. Reason: to subscribe to follow-up replies via email
    Plugin Author Salvatore Fresta

    (@salvatorefresta)

    Hi @fowlerj ,
    this happens ’cause your Nginx installation doesn’t have the module ngx_headers_more:

    https://www.nginx.com/resources/wiki/modules/headers_more/

    it’s not an issue of this plugin

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to overwrite the cache-control header on Nginx?’ is closed to new replies.