## Does Jetty support virtual hosts?

Many domain names can be mapped to a single TCP/IP address. If different content needs to be served for each different domain, then the virtual hosts mechanism needs to be used.

A HttpContext can be registered against one or more virtual host names. Only requests that have a matching host header or fully qualified URL will be passed to that context.

The setVirtualHosts method can be used to set an array of virtual host names on a Context. In the jetty.xml file, this can be done with:

`

      <Call name="addWebApplication">
        <Arg>/context</Arg>
        <Arg>./webapps/myapp</Arg>

        <Set name="virtualHosts">
          <Array type="java.lang.String">
            <Item>www.acme.com</Item>
            <Item>acme.com</Item>
            <Item>www.wileyc.com</Item>
            <Item>184.34.51.125</Item>
          </Array>
        </Set>
      </Call>

`

A null virtual host name is the same as no virtual host names and means the context is available to requests that do not first match other virtual host contexts.

If you want different content to be served from different real IP addresses, then you do not need virtual hosts. Rather you need multiple instances of HttpServer, each with their own listeners and contexts.

JettyFaq