Learn about Centmin Mod LEMP Stack today
Become a Member

Nginx Please advice the correct syntax for Nginx preload and preconnect

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by rdan, Oct 9, 2019.

  1. rdan

    rdan Well-Known Member

    5,452
    1,418
    113
    May 25, 2014
    Ratings:
    +2,212
    Local Time:
    3:40 PM
    Mainline
    10.2
    My current config:

    Code:
    http2_push_preload on;
    
    add_header Link "<https://cdn.domain.com/styles/fonts/roboto-v20.woff2>; as=font; type=font/woff2; crossorigin=anonymous; rel=preload";
    
    add_header Link "<https://cdn.domain.com>; rel=preconnect; probability=1.0";
    


     
  2. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:40 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    preload doesn't need the type specified example

    Code (Text):
    add_header Link '<https://fonts.googleapis.com>; rel=preconnect; crossorigin; probability=1.0;';
    add_header Link '<https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Mu4mxK.woff2>; as=font; crossorigin=anonymous; rel=preload;';
    

    Also for Nginx HTTP/2 Server Push read the proper way to do it conditionally so that it's browser cache aware and only does HTTP/2 Server Push on first vistors and lets browser cache serve subsequent visits Nginx - Nginx HTTP/2 Server Push Finally Supported
     
  3. rdan

    rdan Well-Known Member

    5,452
    1,418
    113
    May 25, 2014
    Ratings:
    +2,212
    Local Time:
    3:40 PM
    Mainline
    10.2
    Thanks Eva.
    Header is added in most pages, but some pages don't have it like XenForo 404 pages.
    So what exact location on Nginx config I must place this to cover all request except static files?
     
  4. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    5:40 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Xenforo 404 would be php generated so most likely needed in your php.conf include file for location for *.php files - though that could make duplicate headers in your location contexts so you'd need to work that out. Though I wouldn't bother with preload for 404 pages to be honest
     
  5. EckyBrazzz

    EckyBrazzz Active Member

    917
    190
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +363
    Local Time:
    4:40 AM
    Latest
    Latest
    Reading my issue

     
  6. EckyBrazzz

    EckyBrazzz Active Member

    917
    190
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +363
    Local Time:
    4:40 AM
    Latest
    Latest
    @eva2000 How can we get this to work on all domains, not only just one.
    There are many files in domains that we want to have with Push Support like the image below (yours)
    6289_cache-aware-http2-push.gif