The serve command
The serve command is used to preview a book by serving it over HTTP at
localhost:3000 by default. Additionally it watches the book's directory for
changes, rebuilding the book and refreshing clients for each change. A websocket
connection is used to trigger the client-side refresh.
Specify a directory
serve command can take a directory as an argument to use as the book's
root instead of the current working directory.
mdbook serve path/to/book
serve has four options: the HTTP port, the WebSocket port, the HTTP hostname
to listen on, and the hostname for the browser to connect to for WebSockets.
For example: suppose you have an nginx server for SSL termination which has a public address of 192.168.1.100 on port 80 and proxied that to 127.0.0.1 on port 8000. To run use the nginx proxy do:
mdbook serve path/to/book -p 8000 -n 127.0.0.1 --websocket-hostname 192.168.1.100
If you were to want live reloading for this you would need to proxy the
websocket calls through nginx as well from
-w flag allows for the websocket port to be
When you use the
-o) flag, mdbook will open the book in your your
default web browser after starting the server.
-d) option allows you to change the output directory for the
book. If not specified it will default to the value of the
book.toml, or to
./book relative to the book's root directory.
serve command is for testing, and is not intended to be a
complete HTTP server for a website.