Skip to content
Toby Chui edited this page Nov 3, 2024 · 1 revision

Custom Headers

You can easily add or remove headers from a proxy rule by editing the proxy rule and select "Custom Headers" options in the "Advanced Settings" field. 圖片

Basic Usage

In the side panel, you will see a few options to add or remove custom headers.

圖片

The blue arrow means the header is added or removed when the request is proxying from Zoraxy to your upstream / origin servers. Which means if the request from your downstream client devices like browser, the header will get modified by this rule.

The opposite goes for the orange arrow. The orange arrow means the header is added or removed when the request is proxying from your upstream server to downstream (client). This option will modify the respond header of your upstream origin server and send it to the downstream device like a web browser.

Request-Specific Variables

Some variables can be used in the value field of a header to modify the downstream to upstream request (aka the blue arrow direction). Require Zoraxy v3.1.2 or above.

  • $host: Represents the hostname from the request. This is the domain name or IP address in the URL (e.g., example.com).
  • $remote_addr: The client’s IP address. This shows the source address from which the request originated.
  • $request_uri: The full requested URI, including the path and query string (e.g., /path/to/resource?arg=value). This is often useful for logging or URL-based rules.
  • $request_method: The HTTP method used in the request, like GET, POST, PUT, etc.
  • $content_length: The size of the request body in bytes, as specified by the Content-Length header. Useful for checking if there’s content in a request (e.g., a file upload).
  • $content_type: The MIME type of the request body, such as application/json or text/html. This can be used to process requests differently based on content type.

Parsed URI Elements

  • $uri: The path part of the URL, excluding the scheme, host, and query string (e.g., /path/to/resource). This is the main part of the URL requested.
  • $args: The raw query string part of the URL (e.g., arg=value&foo=bar). Used if you need to work directly with the unparsed query data.
  • $scheme: The scheme of the URL (http or https). This can be useful for redirects or ensuring secure connections.
  • $query_string: Same as $args, for compatibility reasons.

User Agent and Referer

  • $http_user_agent: The user agent string from the request, identifying the client software (e.g., browser or app) making the request.
  • $http_referer: The URL of the page that referred the client to this request. This can be used for tracking or enforcing access policies based on the referring page.

Advance Settings

There are a few advance settings in place but in general cases, you should not be touching these unless you know what you are doing.

  • Overwrite Host Header: Force overwrite all incoming request to a given hostname, use for legacy php projects that relies on hostname for routing.
  • Remove Hop-by-hop Headers: Remove headers like Connection and Keep-Alive, mostly for debug purpose to check what Zoraxy is actually receiving from downstreams.