• 19 May 2023
  • 1 Minute to read
  • Contributors
  • Dark
  • PDF


  • Dark
  • PDF

Article Summary

Prerender docker middleware

View source on Github.

This standalone docker component can be used as a middleware to prerender your website with when you can't use other middleware (or simply when you prefer to do it this way).



1. Assign a secondary domain to your website.

E.g., if your website is (primary domain), then point (secondary domain) to your website too.


Don't add the secondary domain name as a CNAME for your primary domain; you will need to re-point your primary domain to this docker component at the end of the setup. Use an A or AAAA record instead. Or use a CNAME that your hosting provider provides but doesn't match your primary domain.

2. Edit the Dockerfile to match your settings.

Set your secondary domain, primary domain, and API key. You may want to use environment variables later, but we suggest you do it in the file first to avoid environment compatibility issues during your first setup.

3. Optional

At this point, you can test your setup locally by running the docker container on your computer. For this, you need to have a configured Docker Engine or Docker desktop running on your computer.

make run
curl http://localhost:8080

4. Setup this docker container to run as a standalone server.

This step highly depends on your infrastructure so it's hard to give you more suggestions here. Still, a common step is to upload this dockerfile to a component-based cloud provider, such as Digital Ocean App Platform, Heroku{target= "_blank"}, AWS ECS{target= "_blank"} or Elastic Beanstalk{target= "_blank"}. Or use your already existing, Docker-capable kubernetes cluster, as you like.

5. Point your primary domain to this new component.

At this point you're good to use a CNAME too, as this is a brand new component.

6. Test

Send a few request to your primary domain using curl, and see how it responds to different user agents.

Emulate a normal user request

The user agent could be anything that doesn't look like a bot, we just added something here for clarity.

curl -A Chrome

Emulate a bot request

curl -A Googlebot


You can even set your secondary domain to be authenticated (e.g. with basic auth), so then it will never be indexed by Google, and modify the nginx config to send the authentication along with the request.

Was this article helpful?