0

Goal:

Configure nginx to add a header only on html document without .html extension

Prerequisite:

Add a .html to documents is not possible (they are dynamically generated by another tool via proxy_pass) and they can't be served with .html

What I have tried:

  • add_header directive alone is working but put the header on all resources (css, js, etc.).

  • in server context :

if ($sent_http_content_type ~ "(text/html)") {
    add_header Link '<https://example.com>; rel="preconnect"';
}
  • in http context :
map $sent_http_content_type $link_value {
    text/html '<https://example.com>; rel="preconnect"';
}
add_header Link $link_value;

but none works. I must be wrong with syntax or context...

Someone know how to make it works?

  • The second approach works!! Are there other `add_header` statements in your configuration? What is the exact value of the `Content-Type` response header, for example, does it include a `charset` attribute? – Richard Smith Jul 21 '20 at 17:09
  • @RichardSmith mine has charset attribute, how to handle that? – djmayank Jun 30 '21 at 20:57

0 Answers0