Skip to content

Add Routing Via Config File

Toby Chui edited this page Apr 25, 2024 · 2 revisions

Other than editing routing in the web UI, you can also create a config file and let Zoraxy load it on startup. You can put your config file under conf/proxy/ as JSON file with file extension ".config". For example, here is an example of (ST).test.localhost.config

This config structure is for Zoraxy v3.0.2 or above

{
  "ProxyType": 1,
  "RootOrMatchingDomain": "a.example.com",
  "MatchingDomainAlias": [
    "b.example.com",
    "c.example.com"
  ],
  "Domain": "target.example.com",
  "RequireTLS": true,
  "BypassGlobalTLS": true,
  "SkipCertValidations": false,
  "SkipWebSocketOriginCheck": true,
  "VirtualDirectories": [
    {
      "MatchingPath": "/teacat/",
      "Domain": "sorae.co",
      "RequireTLS": true,
      "SkipCertValidations": false,
      "Disabled": false
    },
    {
      "MatchingPath": "/imus/",
      "Domain": "imuslab.com",
      "RequireTLS": true,
      "SkipCertValidations": true,
      "Disabled": false
    }
  ],
  "UserDefinedHeaders": [
    {
      "Key": "X-Custom-Header",
      "Value": "foo,bar"
    }
  ],
  "RequireBasicAuth": false,
  "BasicAuthCredentials": [
    {
      "Username": "test",
      "PasswordHash": "PASSWORD_SHA512_HASH_HERE"
    },
    {
      "Username": "user",
      "PasswordHash": "PASSWORD_SHA512_HASH_HERE"
    }
  ],
  "BasicAuthExceptionRules": [
    {
      "PathPrefix": "/public/api"
    }
  ],
  "AccessFilterUUID": "default",
  "Disabled": false,
  "DefaultSiteOption": 0,
  "DefaultSiteValue": ""
}

Here is another example that is use for default site (previously named Proxy Root). The file must be named as root.config

{
 "ProxyType": 0,
 "RootOrMatchingDomain": "/",
 "Domain": "imuslab.com",
 "RequireTLS": true,
 "BypassGlobalTLS": false,
 "SkipCertValidations": false,
 "VirtualDirectories": null,
 "RequireBasicAuth": false,
 "BasicAuthCredentials": null,
 "BasicAuthExceptionRules": null,
 "DefaultSiteOption": 1,
 "DefaultSiteValue": "imuslab.com",
 "Disabled": false
}

Here are some key items for the proxy config

  • ProxyType: 0 = root and 1 = host. For root, name your config file root.config
  • RootOrMatchingDomain: Matching rules or keywords, use / for default site router
  • Domain: Proxy target / backend
  • RequireTLS: Proxy target require TLS (https) connection
  • BypassGlobalTLS: Allow this rules to be accessed via port 80 endpoint (if enabled)
  • SkipCertValidations: Skip proxy target TLS error, for self sign certificate
  • SkipWebSocketOriginCheck: Skip websocket origin check, default enable and usually won't cause any security issues
  • AccessFilterUUID: The ID of the access rule filter used, must be matching with the "ID" field inside the access config file