charset_map

The charset_map directive defines a mapping of character sets to their equivalent MIME components in NGINX.

Syntaxcharset_map { charset source_charset destination_charset; ... };
Defaultnone
Contexthttp
Argumentsblock (2)

Description

The charset_map directive allows users to specify how different character sets should be mapped to MIME components within NGINX's HTTP context. This is particularly useful for ensuring that the content served by NGINX correctly identifies its character encoding, which can affect how browsers display content. Each entry in the charset_map block consists of a source character set and a destination character set, providing a way to convert between various encodings when required.

This directive operates in an http context and is configured using a block structure that includes a series of entries formatted as charset source_charset destination_charset;. For example, if a certain character set should be treated as a different one, for instance, mapping latin1 to utf-8, this can be declared in the block. When NGINX processes requests, it looks through this mapping to determine how to handle the character encoding for the content being delivered to clients.

It's important to ensure that the mappings defined are accurate and necessary, as incorrect configurations can lead to improper content rendering on client browsers. Additionally, this can play a vital role in internationalization, where content may need to be served in various languages and encodings depending on user location and preferences.

Config Example

charset_map {
    charset windows-1251 utf-8;
    charset iso-8859-1 utf-8;
};

Ensure all character sets used are supported and recognized by the client browsers.

Overlapping or conflicting character set definitions can lead to unexpected behavior or incorrect content rendering.

Remember to restart NGINX after making changes to the charset map to ensure they take effect.

← Back to all directives