███████╗██╗  ██╗██╗██████╗ ██████╗ ██╗  ██╗███████╗
██╔════╝██║  ██║██║██╔══██╗╚════██╗██║  ██║╚════██║
███████╗███████║██║██████╔╝ █████╔╝███████║    ██╔╝
╚════██║██╔══██║██║██╔═══╝ ██╔═══╝ ╚════██║   ██╔╝ 
███████║██║  ██║██║██║     ███████╗     ██║   ██║  
╚══════╝╚═╝  ╚═╝╚═╝╚═╝     ╚══════╝     ╚═╝   ╚═╝  

Shipl. Buidl. Repetl.

How To: Wildcard domain with Dokku

I like to have a global domain set (eg. example.com) with a wildcard subdomain (*.example.com) and VHOSTS enabled for my apps. This means if I create an app superawesome it will immediately be available as a subdomain on superawesome.example.com.

Problem is that by default even if you type in random-name.example.com a default website will be visible. To quote Dokku’s docs:

By default, dokku will route any received request with an unknown HOST header value to the lexicographically first site in the nginx config stack

In order to limit this routing you can modify your nginx file (/etc/nginx/sites-enabled/default) like so:

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name _;
  return 404;
  log_not_found off;

Then you have to reload your nginx server: sudo service nginx reload

Result of this is that:

  1. superawesome.example.com -> will route to my superawesome app
  2. random-name.example.com -> will return a 404, because an app doesn’t exist
  3. example.com -> will return a 404, because a default app is not set

Fore more details have a look at Dokku’s docs about domain configuration.