Skip to main content
0 reactions

Fixed: Accented Letters Show as é on an nginx Page

Card titled Accented Letters Show as é, labelled Fixed nginx, comparing Café, with no charset so the browser guesses, with Café and a meta charset of utf-8.
An nginx page showed Café until one meta charset line declared it UTF-8

A web page built with OpenTofu® and served by nginx in Docker showed “The Paper Lantern Café” where it should have shown “Café”. Here’s what caused it, and the one line that fixes it.

What I Was Doing

In Part 5 of the OpenTofu Tutorial, the Bookshop page lists books from a variable. One of them is The Paper Lantern Café. OpenTofu writes the page with a heredoc template and uploads it to an nginx container, which serves it at http://localhost:8080. The template started straight with the heading:

main.tf (excerpt)HCL
  home_page = <<EOT
<h1>${local.heading}</h1>
<p>New this week: ${var.featured_book}.</p>

What I Expected

The browser to show the title as written, with its é.

What I Got

The first book read The Paper Lantern Café:

A browser showing the Bookshop book list, where the first book reads The Paper Lantern Café instead of The Paper Lantern Café.
The é in Café shows as é.

What I Checked

A browser learns how a page’s text is encoded from the Content-Type header or from the page itself. I asked nginx for the headers only:

TerminalBash
curl -I http://localhost:8080
OutputPlain text
HTTP/1.1 200 OK
Server: nginx/1.31.10
Date: Sun, 29 Nov 2026 10:38:14 GMT
Content-Type: text/html
Content-Length: 321
Last-Modified: Sun, 29 Nov 2026 10:35:17 GMT
Connection: keep-alive
ETag: "6b0bffe5-141"
Accept-Ranges: bytes

Content-Type: text/html names no character set, and the page didn’t declare one either.

Why It Happens

OpenTofu wrote the page in UTF-8, where é is two bytes. nginx adds a character set to Content-Type only when its charset directive is set, and its default is charset off (nginx: the charset directive (opens in a new tab)). With no encoding given anywhere, the browser guessed another one and showed those two bytes as two characters, Ã and ©.

The HTML Standard says that when the encoding isn’t given in the Content-Type header, the page must declare it with a meta element with a charset attribute, within its first 1024 bytes (HTML Standard: Specifying the document’s character encoding (opens in a new tab)).

The Fix

Make <meta charset="utf-8"> the first line of the page. In the template:

main.tf (excerpt)HCL
  home_page = <<EOT
<meta charset="utf-8">
<h1>${local.heading}</h1>

Then run tofu apply and type yes. OpenTofu replaces the page file and the container’s copy:

Output (the lines that matter)Plain text
Plan: 2 to add, 0 to change, 2 to destroy.

Apply complete! Resources: 2 added, 0 changed, 2 destroyed.

Outputs:

container_name = "bookshop"
website_url = "http://localhost:8080"

Alternative: let nginx send the character set

Setting charset utf-8; in nginx’s configuration adds it to the Content-Type header for every page. It needs your own nginx configuration file in the container, so the meta line is the simpler fix for one page.

After the Fix

Refresh the browser:

The same browser page after the fix, where the first book reads The Paper Lantern Café correctly.
With the encoding declared, Café shows correctly.

The header is unchanged, but the page now declares its encoding, and every accented letter shows correctly.

Common Mistakes

MistakeWhat happensDo this instead
Putting the meta line far down the pageThe HTML Standard requires it within the first 1024 bytes, so the browser may not see it in time.Make it the first line.
Replacing é with &eacute; in the dataIt hides the problem for that one letter only.Declare the encoding once for the whole page.

Troubleshooting

ProblemWhyFix
Accents still wrong after the fixThe browser shows a cached copy of the old page.Reload the page without the cache.
The meta line shows as text on the pageIt was escaped, for example written as &lt;meta.Write the tag itself, <meta charset="utf-8">.

FAQ

Does OpenTofu save files in UTF-8?

Yes. The page held the right bytes; only the browser’s reading of them was wrong.

Do I need the meta line if my page has no accents?

The HTML Standard says yes: a page needs its encoding declared even when every character is plain ASCII.

Conclusion

When nginx serves a page without a character set, declare it in the page: <meta charset="utf-8"> as the first line makes every accented letter show as written.

Additional Resources

OpenTofu® is a registered trademark of LF Projects, LLC. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by the OpenTofu project.

Docker and Docker Desktop are trademarks of Docker, Inc. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by Docker, Inc.

0 comments