arrow-down
    1. Widgets
  1. IAM
    1. Virtual apps
    1. Projects
    2. Layers
        1. AttachmentUploader
        2. Checkbox
        3. Combobox
        4. ContentSelector
        5. ContentTypeFilter
        6. CustomSelector
        7. Date
        8. DateTime
        9. Double
        10. GeoPoint
        11. HtmlArea
        12. ImageSelector
        13. Long
        14. MediaSelector
        15. Radiobutton
        16. Tag
        17. TextArea
        18. TextLine
        19. Time
      1. Field set
      2. Item set
      3. Option set
      4. Mixins
      5. Localization
    3. Content Types
    4. X-data
    5. Macros
    6. Custom styles
    7. Sites
      1. Regions
      2. Part component
      3. Layout component
      4. Text component
      5. Fragments
      6. Filtering
      7. Component indexing
      8. Visual editor
    8. Page templates
    1. Sandboxes
    2. Code
    3. Building
    4. Configuration
    1. Globals
    2. HTTP
    3. Controllers
    4. Filters
    5. Events
    6. Websocket
    7. Error handler
    8. ID provider
    9. Tasks
    10. Localization
    11. Mappings
    12. Components
    13. Processors
    14. Contributions
    15. Templating
    16. Main controller
    17. Java bridge
      1. Webapp Engine
        1. Image service
        2. Component service
      2. Admin Engine
      3. Asset service
      4. HTTP service
      5. IDprovider service
    1. Task engine
    2. Management Endpoint
    3. Statistics Endpoint
    1. Nodes and repos
    2. Properties
    3. Indexing
    4. Branches
    5. Queries (NoQL)
    6. Queries (DSL)
    7. Filters
    8. Aggregations
    9. Highlighting
    10. Editors
    1. Strategies
    2. Distributions
    3. Docker image
    4. Vhosts
    5. Configuration
    6. Backup & restore
    7. Systemd
    8. Clustering
    1. Admin API
    2. Application API
    3. Auditlog API
    4. Authentication API
    5. Cluster API
    6. Common API
    7. Content API
    8. Context API
    9. Event API
    10. Export API
    11. Grid API
    12. I18N API
    13. IO API
    14. Mail API
    15. Node API
    16. Portal API
    17. Project API
    18. Repo API
    19. Scheduler API
    20. Schema API
    21. Tasks API
    22. Value API
    23. VHost API
    24. Websocket API
  2. Audit Logs
    1. Upgrade Notes
    2. Upgrading Apps

Virtual hosts

Contents

Use vhosts to safely expose services (sites/webapps etc) through public domains.

Service mapping

Vhosts essentially serve two purposes, traffic routing and mapping to ID providers.

A single XP runtime instance may offer multiple services. By default, XP provides the following endpoints:

  • localhost:8080/webapp/<app-name>/ (webapp engine)

  • localhost:8080/site/<repo>/<branch>/<path> (site engine)

  • localhost:8080/admin/ (admin engine)

By using vhosts, traffic for specific domains and url patterns may be routed directly to defined service paths in XP.

I.e. example.com -> :8080/site/default/master/homepage

XP XP 7.8.0 7.8.0 Domains can be defined as single host, multiple hosts separated by space and/or regular expressions (started with ~ symbol).

IDN hosts should be specified using Punycode representation.

With vhosts enabled, unexposed services are no longer accessible.

Vhosts may also define the relationship to one or more ID providers. This enables pluggable authentication on a per-vhost basis.

Vhosts only apply to XP service port (defaults to 8080), not the monitoring and management ports.

Request Matching

VHost matches the request if host value matches the requested host AND request-uri matches source.

XP XP 7.8.0 7.8.0 Host matching can be an exact match or regular expression match. Read more about Java Regular Expressions at Pattern JavaDoc Host matching is case-insensitive in both cases.

For backwards compatibility with old versions of XP root domain is not normalized in host. Specify both host values mapping.example.host = example.com. example.com if case you need to support FQDN-style host.
XP XP 7.8.0 7.8.0 host mapping match both www.example.com and example.com hosts
mapping.example.host = www.example.com example.com
XP XP 7.8.0 7.8.0 host mapping will match any sub-domain: 1.example.com, 2.example.com hosts (but not sub-sub-domains)
mapping.example.host = ~[^.]+\\.example\\.com

Source matching is done with "exact" or "starts-with" match. Source matching is case-sensitive, and is done before URI decoding.

source mapping matches any request-uri
mapping.example.source = /
source mapping matches any request-uri that equals to /hello or starts with /hello/
mapping.example.source = /hello

If multiple VHosts match the request, disambiguation rules apply in the following order:

  • XP XP 7.8.0 7.8.0 VHost with lower order value is preferred. If order is not specified, order is considered least preferable (Integer.MAX_VALUE).

  • VHost with the longest source value is preferred.

  • arbitrary VHost is selected.

Capture Groups XP XP 7.8.0 7.8.0

When VHost matched by a host regular expression, capture groups can be used in target via group references.

mapping.example.host = ~example\\.(?<tld>[^.]+)
mapping.example.target = /site/default/master/${tld}

In this example if host is example.no, then target becomes /site/default/master/no

Avoid mixing regular expressions, multiple hosts and capture groups. If host is not matched by regular expression, then group references in target will remain as-is.

Examples

"Example Inc", the owner of "example.com" just finished building their new site. The published site is available on <host>:8080/site/default/master/homepage.

In this case, a vhost configuration looking like this will get the job done:

Sample vhost config file
enabled = true

mapping.example.host = example.com
mapping.example.source = /
mapping.example.target = /site/default/master/homepage

After saving the vhost config file, you should see the following line the XP log:

2019-05-10 11:34:17,234 INFO  c.e.x.w.v.i.c.VirtualHostConfigImpl - Virtual host is enabled and mappings updated.
Each mapping must have a unique mapping identifier, in this case we used example.

Also, "Example Inc" wants the admin console deployed on example.com/admin. To solve this, we will simply add another mapping to the config:

mapping.adm.host = example.com
mapping.adm.source = /admin
mapping.adm.target = /admin
mapping.adm.idProvider.system = default

This time we also added an ID provider to the mapping. This effectively activates system the default (and only) ID provider for this vhost.

Testing vhosts

To verify that your vhost config is working without setting up proxies or modifying your DNS: Simply add the following line to your hosts file.

<host-ip-address>     example.com
Location of hosts file on Mac/Linux_: /etc/hosts, on Windows: c:\Windows\System32\Drivers\etc\hosts

Pointing your browser to http://example.com:8080 will reveal the glorious result.

Visit the vhost configuration section for more details.


Contents

Contents

AI-powered search

Juke AI