nginx

Nginx - How to add multiple values to header


I have a header that is not taking in nginx. Say I have a header such as Strict-Transport-Securty.

add_header Strict-Transport-Security    'max-age=31536000; preload'  always;

Should max-age and preload be separated by a semi-colon and a space? No space? Commas only? How do I include multiple values? The add_header nginx docs don't mention this.


Solution

  • A semicolon is the correct way of separating Strict-Transport-Securty header values. Your line

    add_header Strict-Transport-Security 'max-age=31536000; preload' always;
    

    is correct.


    You probably weren't able to find it in the Nginx docs because this is standardized in the IETF specification:

    Strict-Transport-Security = "Strict-Transport-Security" ":"
                                [ directive ]  *( ";" [ directive ] )

    See here: https://www.rfc-editor.org/rfc/rfc6797#section-6.1