Skip to content

site_url takes not effect on canonical url when running in K8s #4066

Open

Description

@fritzduchardt

I am running mkdocs on K8s at version 1.6.1.

The canonical url rendered in the HTML output looks like this: <link rel="canonical" href="http://0.0.0.0:8000/index.html" />

My mkdocs.yaml looks like this:

site_name: Yummy Stuff
site_url: "https://mydomain.de/"

theme:
  name: readthedocs
docs_dir: docs

copyright: ""
use_directory_urls: false

strict: true

I am starting mkdocs like this:

mkdocs server --dev-addr "0.0.0.0:8000"
I expect the canonical url to be the value from the site_url.

Activity

  1. Shanmukh-l33t commented on Nov 7, 2026

    @Shanmukh-l33t

    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_url is honored.
    • mkdocs serve --dev-addr 0.0.0.0:8123 → <link rel="canonical" href="http://0.0.0.0:8123/index.html" /> — matches your http://0.0.0.0:8000/index.html.

    The serve-time value is deliberate, not a config bug. mkdocs/commands/serve.py does this on purpose before the first build:

    mount_path = urlsplit(config.site_url or '/').path
    config.site_url = serve_url = _serve_url(host, port, mount_path)

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions