Skip to content

Say when mkdocs serve replaces site_url on a public address - #169

Merged
shenxianpeng merged 2 commits into
mainfrom
claude/project-thread-nf3jeu
Nov 7, 2026
Merged

shenxianpeng merged 2 commits into
mainfrom
claude/project-thread-nf3jeu

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

mkdocs serve builds the site with its own address as site_url, so with --dev-addr 0.0.0.0:8000 the canonical link becomes http://0.0.0.0:8000/index.html instead of https://mydomain.de/index.html. That is intended for previews (absolute links must point at the page you are looking at), but people who host a site with mkdocs serve, for example in Kubernetes, end up with wrong canonical links and think site_url is ignored.

This keeps the behavior and makes it visible:

  • When site_url is set and serve listens on a non-loopback address, it logs one INFO line: pages use the dev-server URL instead of site_url, and mkdocs build + a web server is the way to publish. INFO, so --strict is unaffected; loopback addresses and sites without site_url see nothing new.
  • site_url and dev_addr docs say the same.
INFO    -  Pages served by 'mkdocs serve' use http://0.0.0.0:8124/ instead of site_url (https://mydomain.de/) for canonical and other absolute links. To publish the site, run 'mkdocs build' and host the site directory on a web server.

Related Issue

Upstream mkdocs/mkdocs#4066

Checklist

  • New tests added for new behavior (if applicable)
  • Documentation updated (if applicable)
  • Release notes docs/about/release-notes.md updated (if applicable)

mkdocs serve builds the site with its own address as site_url, so the
canonical link becomes http://0.0.0.0:8000/... when it listens on
0.0.0.0. That is right for a preview, but people who host a site with
mkdocs serve (for example in a container) get wrong canonical links
(upstream mkdocs/mkdocs#4066).

Keep the behavior, and when site_url is set and serve listens on a
non-loopback address, log that pages link to the dev server instead of
site_url and that mkdocs build is the way to publish. Document the
same under site_url and dev_addr.
@codspeed

codspeed Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing claude/project-thread-nf3jeu (8fb6af8) with main (19ed1e4)

Open in CodSpeed

@shenxianpeng
shenxianpeng merged commit 9c1b76f into main Nov 7, 2026
25 checks passed
@shenxianpeng
shenxianpeng deleted the claude/project-thread-nf3jeu branch November 7, 2026 07:24

This branch was successfully deployed

1 active deployment
preview — 8fb6af83 Deployed Nov 7, 2026 by shenxianpeng via preview #538
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant