Simple VirtualHost ServerName question

When creating virtual hosts,

Is "ServerName" what distinguishes requests from each other?

Say I had three domains, domain1.com, domain2.com, and domain3.com. They are all set up with DNS to point to my node's IP address.

I should then, create three VirtualHost entries, with ServerName corresponding respectively to each, and specifying separate directories.

But just to make sure, "ServerName" is what determines where each domain goes, even if they're all pointing to the same ip?

For example, I go to example1.com in my browser. Apache loads the VirtualHost who's servername is "www.example1.com" and shows that corresponding directory in the browser?

2 Replies

@sam-the-man:

When creating virtual hosts,

Is "ServerName" what distinguishes requests from each other?

Say I had three domains, domain1.com, domain2.com, and domain3.com. They are all set up with DNS to point to my node's IP address.

I should then, create three VirtualHost entries, with ServerName corresponding respectively to each, and specifying separate directories.

But just to make sure, "ServerName" is what determines where each domain goes, even if they're all pointing to the same ip?

For example, I go to example1.com in my browser. Apache loads the VirtualHost who's servername is "www.example1.com" and shows that corresponding directory in the browser?

Yes, ServerName (as well as ServerAlias) are used for matching the client's Host-header when using name-based virtual hosts.

See http://httpd.apache.org/docs/2.2/vhosts/name-based.html for an overview of name-based virtual hosts and ~~[http://httpd.apache.org/docs/2.2/mod/core.html#servername" target="_blank">](http://httpd.apache.org/docs/2.2/mod/co … servername">http://httpd.apache.org/docs/2.2/mod/core.html#servername](for specifics regarding ServerName.

Basically, yes.

Here are some other guides and documentation:

http://library.linode.com/web-servers/a … ion-basics">http://library.linode.com/web-servers/apache/configuration/configuration-basics

http://httpd.apache.org/docs/2.2/vhosts/

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct