Locally testing a website on its real domain

Posted . Visible to the public.

In rare circumstances, you want to use a websites full domain (say https://mywebsite.com) while testing in dev mode. This can be useful if you need to test third party integrations like embeds, cookie banners, Google Tag Manger or other integrations that allowlist your actual domain.

To achieve this, we will have to

  • make our system resolve mywebsite.com to localhost,
  • run a reverse proxy on localhost:443 with a (locally signed and accepted) SSL certificate for mywebsite.com,
  • forward the traffic to our actual dev server.

On linux, this can be achieved with these steps (instructions for Ubuntu):

Resolving mywebsite.com to 127.0.0.1

Add an entry to /etc/hosts of the form

127.0.0.1 mywebsite.com

Generate an SSL certificate with "mkcert"

  • Install mkcert:
    sudo apt install mkcert libnss3-tools
    
  • Install mkcert as a local certificate authority:
    mkcert -install
    
  • Generate an SSL certificate for you domain:
    mkcert mywebsite.com
    

Set up a reverse proxy using that certificate with "caddy"

  • Install caddy
    sudo apt install caddy
    
  • Disable the global caddy service
    sudo systemctl stop caddy.service
    sudo systemctl disable caddy.service
    
  • Create a file named Caddyfile
    mywebsite.com {
      tls ./name-of-the-generated-cert.pem ./name-of-the-generated-cert-key.pem
      reverse_proxy localhost:3000
    }  
    
  • Start caddy
    sudo caddy run
    
    (This requires sudo because we want to bind to restricted port 443.)

Now you should be able to open your dev server by going to https://mywebsite.com. Don't forget to remove the change to /etc/hosts when you're done testing.

Profile picture of Tobias Kraze
Tobias Kraze
Last edit
Tobias Kraze
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2026-02-24 11:42)