Skip to main content

apache 2.2 - How does ServerName and ServerAlias work?



It's the following part of a virtual host config that I need further clarification on:




# Admin email, Server Name (domain name), and any aliases

ServerAdmin example@example.com
ServerName 141.29.495.999
ServerAlias example.com
...


This is and example config, similar to what I currently have (I don't have a domain name at the moment).



- Allow the following settings for all HTTP requests made on port 80 to IPs that this server can be contacted on. For instance, if the server could be accessed on more than one IP, you could restrict this directive to just one instead of both.




ServerName - If the host part of the HTTP request matches this name, then allow the request. Normally this would be a domain name that maps to an IP, but in this case the HTTP request host must match this IP.



ServerAlias - Alternate names accepted by the server.



The confusing part for me is, in the above scenario, if I set ServerAlias mytestname.com and then made an HTTP request to mytestname.com, there would have to be a DNS record pointing to the server's IP for this to work? In which case, is ServerAlias just basically EXTRA ServerName entries?



Say I had a DNS entry such that foobar.com = 141.29.495.999 but then I had ServerName = 141.29.495.999 and ServerAlias was empty, would that mean that although foobar.com gets resolved to the right IP, because there is no reference to accept foobar.com in ServerName or ServerAlias?



Or something. Man I'm confused.


Answer




Think of it like this:



DNS is the phone directory/yellow pages. When someone wants to call your phone, they can look up your name and get your phone number and call that phone. DNS does the same but for computers - when someone wants to go to www.example.com they ask DNS for the IP address and then they can contact the computer that has that IP address. That is what resolve means. Resolving an IP address has nothing at all to do with Apache; it is strictly a DNS question.



The ServerName and ServerAlias is more like a company's internal phone list. Your webserver is the switchboard; it will accept all incoming connections to the server. Then the client/caller will tell them what name they're looking for, and it will look in the Apache configuration for how to handle that name.



If the name isn't listed as a ServerName/ServerAlias in the apache configuration, apache will always give them the first VirtualHost listed. Or, if there's no VirtualHost at all, it will give the same content no matter what hostname is given in the request.



ETA: So, step by step for a normal connection:





  1. You type http://www.example.com into your browser.

  2. Your computer asks its DNS resolver which IP address it should use when it wants to talk to www.example.com.

  3. Your computer connects to that IP address, and says that it wants to talk to www.example.com (that's the Host:header in HTTP).

  4. The webserver looks at its configuration to figure out what to do with a request for content from www.example.com. Any one of the following may happen:


    • www.example.com is listed as a ServerName or ServerAlias for a VirtualHost - if so, then it will use the configuration for that VirtualHost to deliver the content.

    • The server doesn't have any VirtualHosts at all - if so, then it will use the configuration in its httpd.conf to deliver the content.

    • The server has VirtualHosts but www.example.com isn't listed in any of them - if so, the first Virtualhost in the list will be used to deliver the content.




Comments

Popular posts from this blog

linux - iDRAC6 Virtual Media native library cannot be loaded

When attempting to mount Virtual Media on a iDRAC6 IP KVM session I get the following error: I'm using Ubuntu 9.04 and: $ javaws -version Java(TM) Web Start 1.6.0_16 $ uname -a Linux aud22419-linux 2.6.28-15-generic #51-Ubuntu SMP Mon Aug 31 13:39:06 UTC 2009 x86_64 GNU/Linux $ firefox -version Mozilla Firefox 3.0.14, Copyright (c) 1998 - 2009 mozilla.org On Windows + IE it (unsurprisingly) works. I've just gotten off the phone with the Dell tech support and I was told it is known to work on Linux + Firefox, albeit Ubuntu is not supported (by Dell, that is). Has anyone out there managed to mount virtual media in the same scenario?

hp proliant - Smart Array P822 with HBA Mode?

We get an HP DL360 G8 with an Smart Array P822 controller. On that controller will come a HP StorageWorks D2700 . Does anybody know, that it is possible to run the Smart Array P822 in HBA mode? I found only information about the P410i, who can run HBA. If this is not supported, what you think about the LSI 9207-8e controller? Will this fit good in that setup? The Hardware we get is used but all original from HP. The StorageWorks has 25 x 900 GB SAS 10K disks. Because the disks are not new I would like to use only 22 for raid6, and the rest for spare (I need to see if the disk count is optimal or not for zfs). It would be nice if I'm not stick to SAS in future. As OS I would like to install debian stretch with zfs 0.71 as file system and software raid. I have see that hp has an page for debian to. I would like to use hba mode because it is recommend, that zfs know at most as possible about the disk, and I'm independent from the raid controller. For us zfs have many benefits,

apache 2.2 - Server Potentially Compromised -- c99madshell

So, low and behold, a legacy site we've been hosting for a client had a version of FCKEditor that allowed someone to upload the dreaded c99madshell exploit onto our web host. I'm not a big security buff -- frankly I'm just a dev currently responsible for S/A duties due to a loss of personnel. Accordingly, I'd love any help you server-faulters could provide in assessing the damage from the exploit. To give you a bit of information: The file was uploaded into a directory within the webroot, "/_img/fck_uploads/File/". The Apache user and group are restricted such that they can't log in and don't have permissions outside of the directory from which we serve sites. All the files had 770 permissions (user rwx, group rwx, other none) -- something I wanted to fix but was told to hold off on as it wasn't "high priority" (hopefully this changes that). So it seems the hackers could've easily executed the script. Now I wasn't able