How does ServerName and ServerAlias work?Difference between ServerName and ServerAliaswhy do we have to use ServerName for our websites in apache?Apache2 shared server: default webpageWhat will happen if client call Apache server by IP and there are two SNI virtual hostsApache is taking requests for all subdomains leading always to the same virtual hostHow do I protect random people pointing their domain to my server?Apache accepting requests to other servers?mod_rewrite - RewriteCond if %HTTP_HOST is NOT any ServerName/ServerAliasDNS not resolving 3rd level sub domainMy Apache installation isn't showing default site after adding a virtual hostHow to disable default VirtualHost in apache2?Apache2 multiple hostnames redirected to oneapache2 configuration for blog.example.com not workingIgnoring ServerName in Apache2Performance of multiple VirtualHosts vs. ServerAlias in Apache2?Prevent using wildcard in Apache server alias settingDifference between ServerName and ServerAliasHow can I get ServerAlias to work?Virtual hosts with port 80 & 443 not workingVirtualHost's server name does not work (shows /var/www), all aliases do

Ribbon Cable Cross Talk - Is there a fix after the fact?

How to safely discharge oneself

Shell builtin `printf` line limit?

How to make Flex Markers appear in Logic Pro X?

Why is Ni[(PPh₃)₂Cl₂] tetrahedral?

Are there any tips to help hummingbirds find a new feeder?

To exponential digit growth and beyond!

Illustrating that universal optimality is stronger than sphere packing

nginx conf: http2 module not working in Chrome in ubuntu 18.04

What is the winged creature on the back of the Mordenkainen's Tome of Foes book?

How to become an Editorial board member?

Coloring lines in a graph the same color if they are the same length

Department head said that group project may be rejected. How to mitigate?

Does attacking (or having a rider attack) cancel Charge/Pounce-like abilities?

Salesforce bug enabled "Modify All"

Proto-Indo-European (PIE) words with IPA

What pc resources are used when bruteforcing?

How did the Allies achieve air superiority on Sicily?

Efficient Algorithms for Destroyed Document Reconstruction

Is ideal gas incompressible?

What is the required burn to keep a satellite at a Lagrangian point?

Keeping the dodos out of the field

How can I reduce the size of matrix?

Why is this integration method not valid?



How does ServerName and ServerAlias work?


Difference between ServerName and ServerAliaswhy do we have to use ServerName for our websites in apache?Apache2 shared server: default webpageWhat will happen if client call Apache server by IP and there are two SNI virtual hostsApache is taking requests for all subdomains leading always to the same virtual hostHow do I protect random people pointing their domain to my server?Apache accepting requests to other servers?mod_rewrite - RewriteCond if %HTTP_HOST is NOT any ServerName/ServerAliasDNS not resolving 3rd level sub domainMy Apache installation isn't showing default site after adding a virtual hostHow to disable default VirtualHost in apache2?Apache2 multiple hostnames redirected to oneapache2 configuration for blog.example.com not workingIgnoring ServerName in Apache2Performance of multiple VirtualHosts vs. ServerAlias in Apache2?Prevent using wildcard in Apache server alias settingDifference between ServerName and ServerAliasHow can I get ServerAlias to work?Virtual hosts with port 80 & 443 not workingVirtualHost's server name does not work (shows /var/www), all aliases do






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








58















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



<VirtualHost *:80>
# 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).



<VirtualHost *:80> - 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.










share|improve this question



















  • 1





    You forgot some words in the 2nd-last paragraph. :-)

    – ThatGraemeGuy
    Jul 2 '13 at 14:05

















58















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



<VirtualHost *:80>
# 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).



<VirtualHost *:80> - 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.










share|improve this question



















  • 1





    You forgot some words in the 2nd-last paragraph. :-)

    – ThatGraemeGuy
    Jul 2 '13 at 14:05













58












58








58


40






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



<VirtualHost *:80>
# 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).



<VirtualHost *:80> - 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.










share|improve this question
















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



<VirtualHost *:80>
# 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).



<VirtualHost *:80> - 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.







apache-2.2 domain-name-system






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 2 '13 at 15:19









blau

60339




60339










asked Jul 2 '13 at 14:00









njpnjp

393146




393146







  • 1





    You forgot some words in the 2nd-last paragraph. :-)

    – ThatGraemeGuy
    Jul 2 '13 at 14:05












  • 1





    You forgot some words in the 2nd-last paragraph. :-)

    – ThatGraemeGuy
    Jul 2 '13 at 14:05







1




1





You forgot some words in the 2nd-last paragraph. :-)

– ThatGraemeGuy
Jul 2 '13 at 14:05





You forgot some words in the 2nd-last paragraph. :-)

– ThatGraemeGuy
Jul 2 '13 at 14:05










3 Answers
3






active

oldest

votes


















98














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 VirtualHostto 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.






share|improve this answer

























  • So, if the host part of an HTTP request is www.example.com, the DNS will resolve the IP address for that name, and the HTTP request host part will actually be an IP; upon reaching the server, apache will also know that the request asked for www.example.com and if there's a ServerName or ServerAlias directive for that domain name, it can serve the document root?

    – njp
    Jul 2 '13 at 14:26











  • No - the HTTP request part is still the hostname. I'll clarify a little more.

    – Jenny D
    Jul 2 '13 at 14:45











  • 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.. I tested this. It is right but I am not sure it is first Virtualhost. Thank you for information. +1

    – S.M.Mousavi
    Apr 27 '16 at 11:43



















17














If you don't define ServerName, then apache2 will try to guess it from /etc/hosts. ServerAlias is optional. The most usual use case is where



ServerName example.com
ServerAlias www.example.com


It's up to you (not apache2's job) to make sure that requests reach the webserver IP, e.g, registering a domain and setting up DNS records. A very common way to do so (for test & development) without domain and dns records is to set your local machine /etc/hosts file so that example.com points to the IP of your server.



192.168.0.12 example.com
192.168.0.12 www.example.com





share|improve this answer






























    0














    I would strongly suggest to read the official documentation on the topic : https://httpd.apache.org/docs/2.4/vhosts/name-based.html



    it says "If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used." . So in your case if you access "foobar.com", the first VirtualHost entry who somehow matches the IP 141.29.495.999 would be used by httpd



    The same document says "Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive,". So you can regard ServerAlias simply as additional ServerName entries.






    share|improve this answer

























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "2"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f520195%2fhow-does-servername-and-serveralias-work%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      98














      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 VirtualHostto 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.






      share|improve this answer

























      • So, if the host part of an HTTP request is www.example.com, the DNS will resolve the IP address for that name, and the HTTP request host part will actually be an IP; upon reaching the server, apache will also know that the request asked for www.example.com and if there's a ServerName or ServerAlias directive for that domain name, it can serve the document root?

        – njp
        Jul 2 '13 at 14:26











      • No - the HTTP request part is still the hostname. I'll clarify a little more.

        – Jenny D
        Jul 2 '13 at 14:45











      • 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.. I tested this. It is right but I am not sure it is first Virtualhost. Thank you for information. +1

        – S.M.Mousavi
        Apr 27 '16 at 11:43
















      98














      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 VirtualHostto 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.






      share|improve this answer

























      • So, if the host part of an HTTP request is www.example.com, the DNS will resolve the IP address for that name, and the HTTP request host part will actually be an IP; upon reaching the server, apache will also know that the request asked for www.example.com and if there's a ServerName or ServerAlias directive for that domain name, it can serve the document root?

        – njp
        Jul 2 '13 at 14:26











      • No - the HTTP request part is still the hostname. I'll clarify a little more.

        – Jenny D
        Jul 2 '13 at 14:45











      • 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.. I tested this. It is right but I am not sure it is first Virtualhost. Thank you for information. +1

        – S.M.Mousavi
        Apr 27 '16 at 11:43














      98












      98








      98







      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 VirtualHostto 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.






      share|improve this 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 VirtualHostto 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.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 25 '16 at 3:33









      JakeGould

      3,2491836




      3,2491836










      answered Jul 2 '13 at 14:07









      Jenny DJenny D

      24.4k116296




      24.4k116296












      • So, if the host part of an HTTP request is www.example.com, the DNS will resolve the IP address for that name, and the HTTP request host part will actually be an IP; upon reaching the server, apache will also know that the request asked for www.example.com and if there's a ServerName or ServerAlias directive for that domain name, it can serve the document root?

        – njp
        Jul 2 '13 at 14:26











      • No - the HTTP request part is still the hostname. I'll clarify a little more.

        – Jenny D
        Jul 2 '13 at 14:45











      • 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.. I tested this. It is right but I am not sure it is first Virtualhost. Thank you for information. +1

        – S.M.Mousavi
        Apr 27 '16 at 11:43


















      • So, if the host part of an HTTP request is www.example.com, the DNS will resolve the IP address for that name, and the HTTP request host part will actually be an IP; upon reaching the server, apache will also know that the request asked for www.example.com and if there's a ServerName or ServerAlias directive for that domain name, it can serve the document root?

        – njp
        Jul 2 '13 at 14:26











      • No - the HTTP request part is still the hostname. I'll clarify a little more.

        – Jenny D
        Jul 2 '13 at 14:45











      • 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.. I tested this. It is right but I am not sure it is first Virtualhost. Thank you for information. +1

        – S.M.Mousavi
        Apr 27 '16 at 11:43

















      So, if the host part of an HTTP request is www.example.com, the DNS will resolve the IP address for that name, and the HTTP request host part will actually be an IP; upon reaching the server, apache will also know that the request asked for www.example.com and if there's a ServerName or ServerAlias directive for that domain name, it can serve the document root?

      – njp
      Jul 2 '13 at 14:26





      So, if the host part of an HTTP request is www.example.com, the DNS will resolve the IP address for that name, and the HTTP request host part will actually be an IP; upon reaching the server, apache will also know that the request asked for www.example.com and if there's a ServerName or ServerAlias directive for that domain name, it can serve the document root?

      – njp
      Jul 2 '13 at 14:26













      No - the HTTP request part is still the hostname. I'll clarify a little more.

      – Jenny D
      Jul 2 '13 at 14:45





      No - the HTTP request part is still the hostname. I'll clarify a little more.

      – Jenny D
      Jul 2 '13 at 14:45













      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.. I tested this. It is right but I am not sure it is first Virtualhost. Thank you for information. +1

      – S.M.Mousavi
      Apr 27 '16 at 11:43






      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.. I tested this. It is right but I am not sure it is first Virtualhost. Thank you for information. +1

      – S.M.Mousavi
      Apr 27 '16 at 11:43














      17














      If you don't define ServerName, then apache2 will try to guess it from /etc/hosts. ServerAlias is optional. The most usual use case is where



      ServerName example.com
      ServerAlias www.example.com


      It's up to you (not apache2's job) to make sure that requests reach the webserver IP, e.g, registering a domain and setting up DNS records. A very common way to do so (for test & development) without domain and dns records is to set your local machine /etc/hosts file so that example.com points to the IP of your server.



      192.168.0.12 example.com
      192.168.0.12 www.example.com





      share|improve this answer



























        17














        If you don't define ServerName, then apache2 will try to guess it from /etc/hosts. ServerAlias is optional. The most usual use case is where



        ServerName example.com
        ServerAlias www.example.com


        It's up to you (not apache2's job) to make sure that requests reach the webserver IP, e.g, registering a domain and setting up DNS records. A very common way to do so (for test & development) without domain and dns records is to set your local machine /etc/hosts file so that example.com points to the IP of your server.



        192.168.0.12 example.com
        192.168.0.12 www.example.com





        share|improve this answer

























          17












          17








          17







          If you don't define ServerName, then apache2 will try to guess it from /etc/hosts. ServerAlias is optional. The most usual use case is where



          ServerName example.com
          ServerAlias www.example.com


          It's up to you (not apache2's job) to make sure that requests reach the webserver IP, e.g, registering a domain and setting up DNS records. A very common way to do so (for test & development) without domain and dns records is to set your local machine /etc/hosts file so that example.com points to the IP of your server.



          192.168.0.12 example.com
          192.168.0.12 www.example.com





          share|improve this answer













          If you don't define ServerName, then apache2 will try to guess it from /etc/hosts. ServerAlias is optional. The most usual use case is where



          ServerName example.com
          ServerAlias www.example.com


          It's up to you (not apache2's job) to make sure that requests reach the webserver IP, e.g, registering a domain and setting up DNS records. A very common way to do so (for test & development) without domain and dns records is to set your local machine /etc/hosts file so that example.com points to the IP of your server.



          192.168.0.12 example.com
          192.168.0.12 www.example.com






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 2 '13 at 14:13









          blaublau

          60339




          60339





















              0














              I would strongly suggest to read the official documentation on the topic : https://httpd.apache.org/docs/2.4/vhosts/name-based.html



              it says "If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used." . So in your case if you access "foobar.com", the first VirtualHost entry who somehow matches the IP 141.29.495.999 would be used by httpd



              The same document says "Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive,". So you can regard ServerAlias simply as additional ServerName entries.






              share|improve this answer





























                0














                I would strongly suggest to read the official documentation on the topic : https://httpd.apache.org/docs/2.4/vhosts/name-based.html



                it says "If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used." . So in your case if you access "foobar.com", the first VirtualHost entry who somehow matches the IP 141.29.495.999 would be used by httpd



                The same document says "Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive,". So you can regard ServerAlias simply as additional ServerName entries.






                share|improve this answer



























                  0












                  0








                  0







                  I would strongly suggest to read the official documentation on the topic : https://httpd.apache.org/docs/2.4/vhosts/name-based.html



                  it says "If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used." . So in your case if you access "foobar.com", the first VirtualHost entry who somehow matches the IP 141.29.495.999 would be used by httpd



                  The same document says "Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive,". So you can regard ServerAlias simply as additional ServerName entries.






                  share|improve this answer















                  I would strongly suggest to read the official documentation on the topic : https://httpd.apache.org/docs/2.4/vhosts/name-based.html



                  it says "If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used." . So in your case if you access "foobar.com", the first VirtualHost entry who somehow matches the IP 141.29.495.999 would be used by httpd



                  The same document says "Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive,". So you can regard ServerAlias simply as additional ServerName entries.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 9 at 17:03

























                  answered Jan 9 at 16:41









                  Pierluigi VernettoPierluigi Vernetto

                  1012




                  1012



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Server Fault!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f520195%2fhow-does-servername-and-serveralias-work%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

                      Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

                      Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020