61

In Apache2 is it possible to set multiple ServerNames in one VHost?

I want to setup a "wiki" vhost for an internal wiki.

My network has a ".lan" suffix. How do I get Apache to answer both "wiki" and "wiki.lan" on the same vhost?

2 Answers 2

81

Use both the ServerName and ServerAlias directives in your virtualhost definition. You would do something like:

<VirtualHost *:80>

    Servername wiki.lan 
    ServerAlias wiki

    [...]

</Virtualhost>

See Apache Docs – ServerAlias Directive.

3
  • Thats right! I had forgotten about ServerAlias...
    – Soviero
    Jul 27, 2011 at 6:41
  • 7
    Does it make a difference which name is specified at ServerName and ServerAlias? Can it be exchanged?
    – robsch
    Oct 30, 2018 at 9:15
  • ServerName is the one used when apache can not figure which host to use. E.g. when connecting using an IP address instead of a hostname. Sep 1, 2021 at 17:08
38

Add the other names with ServerAlias.

You can use any of those 2 formats or a mixture:

ServerAlias aaa.example.com bbb.example.com ccc.example.com

ServerAlias ddd.example.com
ServerAlias eee.example.com
ServerAlias fff.example.com

The directive is valid only in VirtualHost section.

See: http://httpd.apache.org/docs/current/mod/core.html#serveralias

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.