Run as a service on Windows
You can install cloudflared as a system service on Windows.
Configure cloudflared as a service
By default, Cloudflare Tunnel expects all of the configuration to exist in the %USERPROFILE%\.cloudflared\config.yml configuration file. At a minimum you must specify the following arguments to run as a service:
| Argument | Description |
|---|---|
tunnel |
The UUID of your tunnel |
credentials-file |
The location of the credentials file for your tunnel |
Run cloudflared as a service
-
Download the latest
cloudflaredversion. -
Create a new directory:
-
Copy the
.exefile you downloaded in step 1 to the new directory and rename it tocloudflared.exe. -
Open CMD as an administrator and go to
C:\Cloudflared\bin. -
Run this command to install
cloudflared: -
Next, run this command to create another directory:
-
Log in and authenticate
cloudflared: -
The login command will generate a
cert.pemfile and save it to your user profile by default. Copy the file to the.cloudflaredfolder created in step 5 using this command: -
Next, create a tunnel:
This will generate a credentials file in
.jsonformat. -
Create a configuration file with the following content:
-
Copy the credentials file to the folder created in step 6:
-
Validate the ingress rule entries in your configuration file using the command:
-
In the Registry Editor, go to
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cloudflared. -
In the Cloudflared registry entry, modify
ImagePathto point to thecloudflared.exeandconfig.ymlfiles. Make sure that there are no extra spaces or characters while you modify the registry entry, as this could cause problems with starting the service. -
If the service does not start, run the following command from
C:\Cloudflared\bin:You will see the output below:
Next steps
You can now route traffic through your tunnel. If you add IP routes or otherwise change the configuration, restart the service to load the new configuration: