xml_entities
The 'xml_entities' directive enables or disables the encoding of XML entities in NGINX responses.
Description
The 'xml_entities' directive controls how XML entities are processed within NGINX, particularly affecting the representation of certain characters in XML documents served by the server. When enabled, this directive ensures that special characters, such as <, >, and &, are properly encoded into their corresponding XML entity references, helping conform to XML standards. This is particularly important when serving XML files or applications that utilize XML data structures to ensure that the data integrity is maintained, preventing misinterpretation by XML parsers.
When set, any instance of characters that have specific meanings in XML will be replaced with their respective entity references whenever the server generates a response that includes XML content. This helps avoid potential parsing errors for clients expecting well-formed XML. The directive can be placed in various contexts such as http, server, and location, allowing a fine-grained control over responses based on where it is applied.
The directive takes a single argument: either on to enable entity encoding, or off to disable it. If the directive is set to 'off', NGINX will serve XML data without encoding the special characters into entities, which might lead to incorrect processing by XML consumers.
Config Example
http {
xml_entities on;
server {
location /api {
xml_entities on;
}
}
}Ensure it is not conflicting with other directives that handle output formatting.
Don't enable XML entities if you are serving plain text content, as it may lead to unnecessary overhead.