Vhosts and Routing
When you create a Site, ForgeKit takes care of all the routing and the ports without you needing to worry about it.
Here's how it works.
http://myproject.test → windows hosts file → Forgekit router(port 80) → Web Server Instance(port 8080) → \ForgeKit\sites\myproject
Because of the ForgeKit Router which listens to port 80, you don't need to write locahost:80 or localhost:8080 in the browser. Entering the site's domain will automatically make ForgeKit find it's proper web-server, then it's Vhost configuration on that server and serve you the right site code and configs.
Hosts file mapping
On Windows, ForgeKit uses the hosts file so your domain resolves to localhost. It will create a code block in that file which it will update every time you make a change to a site or config. Ex:
# --- ForgeKit hosts START - don't edit inside this---
127.0.0.1 forgekit.test # ForgeKit
127.0.0.1 mindstare.test # ForgeKit
127.0.0.1 myfirst.test # ForgeKit
127.0.0.1 myproject.dev # ForgeKit
127.0.0.1 prod1.test # ForgeKit
# --- ForgeKit hosts END ---
This requires admin privileges because Windows protects the hosts file. ForgeKit only requests elevation when it needs to update hosts entries.
The first time you ask ForgeKit to make a change there, it will ask for your permission. If accepted, it will create a task inside task scheduler in Windows, which will remember that permission. On subsequent requests, ForgeKit will just run that task to update the hosts file without needing to ask for permission every single time.
Vhost generation
ForgeKit writes vhost rules into the Instance config so the web server knows:
- which domain it is serving
- which folder is the document root
- how to route requests
This will be in the web server's instance of vhosts.conf. Ex:
# This file is managed by ForgeKit. Manual edits may be overwritten.
# --- ForgeKit site: forgekit.test (site-9da4994479c262e04c8f4bc6f7244b50) ---
<VirtualHost *:8081>
ServerName forgekit.test
DocumentRoot "C:\ForgeKit\sites\forgekit-site\public"
<Directory "C:\ForgeKit\sites\forgekit-site\public">
AllowOverride All
Require all granted
</Directory>
ErrorLog "C:\ForgeKit\instances\web\web-apache-2-4-65-1\logs\forgekit.test-error.log"
CustomLog "C:\ForgeKit\instances\web\web-apache-2-4-65-1\logs\forgekit.test-access.log" common
</VirtualHost>
# --- ForgeKit site: myproject.dev (site-ee51bfee99cf9bfcf9b43d2fdaaa5ef9) ---
<VirtualHost *:8081>
ServerName myproject.dev
DocumentRoot "C:\ForgeKit\sites\forgekit"
<Directory "C:\ForgeKit\sites\forgekit">
AllowOverride All
Require all granted
</Directory>
ErrorLog "C:\ForgeKit\instances\web\web-apache-2-4-65-1\logs\myproject.dev-error.log"
CustomLog "C:\ForgeKit\instances\web\web-apache-2-4-65-1\logs\myproject.dev-access.log" common
</VirtualHost>
Framework roots (Laravel / WordPress)
Some frameworks require a public web root.
If your project is Laravel, your site root should usually be:
your-laravel-project/public
Same idea applies to other frameworks that separate the entry point.
Troubleshooting routing
Domain resolves but page doesn’t load
- Check Instance is running
- Check the site is assigned to an Instance
- Check the site root folder exists and has an index.php or index.html inside of it
Wrong site opens / redirects happen
- Avoid real public domains
- Prefer
.testdomains - Clear browser HSTS/HTTPS rules if you previously used the same domain
Continue to → SSL and HTTPS