You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
site_url takes not effect on canonical url when running in K8s #4066
The canonical url rendered in the HTML output looks like this: <link rel="canonical" href="http://0.0.0.0:8000/index.html" />
Reproduced both halves of this on 1.6.1 with your exact config (site_url: "https://mydomain.de/", readthedocs theme, use_directory_urls: false):
and re-applies it on every rebuild. mkdocs serve is the livereload dev server: every generated absolute URL (canonical, links to other pages, what a sitemap would contain) has to resolve against the preview server, otherwise navigation jumps out of the preview to production while you're editing. Only the mount path of your site_url survives, which is why the host/port switch to --dev-addr but the path doesn't.
So the K8s setup here is the actual issue: serve isn't meant to publish the site. For production, mkdocs build in the image and serve site_dir from your web server (or mkdocs gh-deploy) gives https://mydomain.de/index.html as canonical — verified above.
If you want serve to keep pinning canonical to site_url while still serving from --dev-addr, that would be a behavior change to the dev server rather than a fix for site_url handling — worth raising as an idea with the maintainers first.
Activity
Shanmukh-l33t commentedon Nov 7, 2026
Reproduced both halves of this on 1.6.1 with your exact config (
site_url: "https://mydomain.de/", readthedocs theme,use_directory_urls: false):mkdocs build --strict→<link rel="canonical" href="https://mydomain.de/index.html" />—site_urlis honored.mkdocs serve --dev-addr 0.0.0.0:8123→<link rel="canonical" href="http://0.0.0.0:8123/index.html" />— matches yourhttp://0.0.0.0:8000/index.html.The serve-time value is deliberate, not a config bug.
mkdocs/commands/serve.pydoes this on purpose before the first build:and re-applies it on every rebuild.
mkdocs serveis the livereload dev server: every generated absolute URL (canonical, links to other pages, what a sitemap would contain) has to resolve against the preview server, otherwise navigation jumps out of the preview to production while you're editing. Only the mount path of yoursite_urlsurvives, which is why the host/port switch to--dev-addrbut the path doesn't.So the K8s setup here is the actual issue:
serveisn't meant to publish the site. For production,mkdocs buildin the image and servesite_dirfrom your web server (ormkdocs gh-deploy) giveshttps://mydomain.de/index.htmlas canonical — verified above.If you want
serveto keep pinning canonical tosite_urlwhile still serving from--dev-addr, that would be a behavior change to the dev server rather than a fix forsite_urlhandling — worth raising as an idea with the maintainers first.Say when mkdocs serve replaces site_url on a public address (#169)