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:
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é:

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:
curl -I http://localhost:8080
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:
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:
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 header is unchanged, but the page now declares its encoding, and every accented letter shows correctly.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Putting the meta line far down the page | The 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 é in the data | It hides the problem for that one letter only. | Declare the encoding once for the whole page. |
Troubleshooting
| Problem | Why | Fix |
|---|---|---|
| Accents still wrong after the fix | The browser shows a cached copy of the old page. | Reload the page without the cache. |
The meta line shows as text on the page | It was escaped, for example written as <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
- HTML Standard: Specifying the document’s character encoding (opens in a new tab)
- nginx: the charset directive (opens in a new tab)
- Strings and Templates (opens in a new tab)
Related
- OpenTofu Tutorial — Part 5: Locals, Expressions and tofu console
- OpenTofu String Templates and Heredocs Explained
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