Chapter 14. Advanced Virtual Host Configuration

This chapter will discuss advanced topics related to virtual host configuration.

Each virtual host is supposed to match its origin. (a domain or an IP) But sometimes a virtual host has to be connected to others, or the other way round. Depending on functionalities, Client Statistics / Access Log policies might be different.

URL Preprocessing

Regular expressions are used to modify the requested URLs. If URL preprocessing is defined, all client requests (HTTP or File I/O) must pass through the URL Rewriter.

../_images/urlrewrite1.png

The request can only reach the virtual host by passing through the URL Rewriter.

If an approaching Host name is modified by the URL Rewriter, then it will consider it as if the Host header was modified by the client’s HTTP request. URL preprocessing is configured in the virtual host settings (vhosts.xml). While most settings are under the virtual host, URL preprocessing can change the name of the Host requested by the client, so the settings must be on the same level as the virtual host.

# vhosts.xml

<Vhosts>
   <Vhost ...> ... </Vhost>
   <Vhost ...> ... </Vhost>
   <URLRewrite ...> ... </URLRewrite>
   <URLRewrite ...> ... </URLRewrite>
</Vhosts>

Multiple configurations are allowed, and the regular expressions will be checked in order.

# vhosts.xml - <Vhosts>

<URLRewrite AccessLog="Replace">
    <Pattern>www.example.com/([^/]+)/(.*)</Pattern>
    <Replace>#1.example.com/#2</Replace>
</URLRewrite>
  • <URLRewrite>

    Configures URL preprocessing. AccessLog (default: Replace) Configures URLs that will be recorded in the Access log. Replace records URLs after processing (/logo.jpg), while Pattern records URLs after processing (/baseball/logo.jpg).

    • <Pattern> Configures the patterns to be matched. A single pattern is expressed with parentheses ().
    • <Replace> Configures the conversion format. Patterns that match can be used with expressions like #1 and #2. #0 stands for the entire requested URL. A maximum of nine patterns (up to #9) can be configured.

Throughput is provided by Chapter 10. Monitoring & Statistics and can also be checked via Successful URL Preprocessing. URL preprocessing can work alongside Trimming and MP4 HLS to simplify expressions further.

# vhosts.xml - <Vhosts>

<URLRewrite>
    <Pattern>example.com/([^/]+)/(.*)</Pattern>
    <Replace>example.com/#1.php?id=#2</Replace>
</URLRewrite>
// Pattern : example.com/releasenotes/1.3.4
// Replace : example.com/releasenotes.php?id=1.3.4

<URLRewrite>
    <Pattern>example.com/download/(.*)</Pattern>
    <Replace>download.example.com/#1</Replace>
</URLRewrite>
// Pattern : example.com/download/1.3.4
// Replace : download.example.com/1.3.4

<URLRewrite>
    <Pattern>example.com/img/(.*\.(jpg|png).*)</Pattern>
    <Replace>example.com/#1/STON/composite/watermark1</Replace>
</URLRewrite>
// Pattern : example.com/img/image.jpg?date=20140326
// Replace : example.com/image.jpg?date=20140326/STON/composite/watermark1

<URLRewrite>
    <Pattern>example.com/preview/(.*)\.(mp3|mp4|m4a)$</Pattern>
    <Replace><![CDATA[example.com/#1.#2?&end=30&boost=10&bandwidth=2000&ratio=100]]></Replace>
</URLRewrite>
// Pattern : example.com/preview/audio.m4a
// Replace : example.com/audio.m4a?end=30&boost=10&bandwidth=2000&ratio=100

<URLRewrite>
    <Pattern>example.com/(.*)\.mp4\.m3u8$</Pattern>
    <Replace>example.com/#1.mp4/mp4hls/index.m3u8</Replace>
</URLRewrite>
// Pattern : example.com/video.mp4.m3u8
// Replace : example.com/video.mp4/mp4hls/index.m3u8

<URLRewrite>
    <Pattern>example.com/(.*)_(.*)_(.*)</Pattern>
    <Replace>example.com/#0/#1/#2/#3</Replace>
</URLRewrite>
// Pattern : example.com/video.mp4_10_20
// Replace : example.com/example.com/video.mp4_10_20/video.mp4/10/20

If one of the five special XML characters are used, then the pattern must be surrounded with a <![CDATA[ … ]]> tag. If configured using Chapter 13. WM (Web Management), all patterns are processed as CDATA.

Facade Virtual Host

Because <Alias> is just a nickname for the virtual host, it will not provide separate statistics and logs. If you want to use the same virtual host but obtain different Client Statistics and Access Log depending on the domain, a Facade Virtual Host can be configured.

# vhosts.xml - <Vhosts>

<Vhost Name="example.com">
   ...
</Vhost>

<Vhost Name="another.com" Status="facade:example.com">
   ...
</Vhost>

This can be done by inputting facade: + virtual host into the Status property. In the previous example, the Client Statistics and Access Log will be recorded for clients that request another.com, not example.com.

Sub-Path

A single virtual host can have different sub-paths. These sub-paths can be configured to be handled by separate virtual hosts.

# vhosts.xml - <Vhosts>

<Vhost Name="sports.com">
  <Sub Status="Active">
    <Path Vhost="baseball.com">/baseball/<Path>
    <Path Vhost="football.com">/football/<Path>
    <Path Vhost="photo.com">/*.jpg<Path>
  </Sub>
</Vhost>

<Vhost Name="baseball.com" />
<Vhost Name="football.com" />
<Vhost Name="photo.com" />
  • If the page path or pattern matches the <Sub> input, then it will be sent to the corresponding virtual host. If they do not match, then the page will be handled by the current virtual host.

    • Status (default: Active) Sub-paths are ignored when inactive.

    • <Path> If the URI requested by the client and the path match, the request will be sent to Vhost. Only paths or patterns are allowed.

      <Path Vhost="baseball.com">baseball<Path>
      <Path Vhost="photo.com">*.jpg<Path>
      

      If input as above, they will be parsed as /baseball/ and /*.jpg, respectively.

For example, if the client requests the following, the request will be sent to the football.com virtual host.

GET /football/rank.html HTTP/1.1
Host: sports.com

Redirect Tracing

When the origin server responds with the Redirect responses (301, 302, 303, 307), the location header is tracked to request the content.

../_images/conf_redirectiontrace.png

The redirection is hidden from the client.

# server.xml - <Server><VHostDefault><OriginOptions>
# vhosts.xml - <Vhosts><Vhost><OriginOptions>

<RedirectionTrace>OFF</RedirectionTrace>
  • <RedirectionTrace>
    • OFF (default) Saved as 3xx responses.
    • ON Downloads content from the address specified in the location header.

      Works only if matched to the format or with a valid Location header.       Traced only once to prevent infinite redirects.