How configure apache (vhost) for Server-Hostname












1














First of all, sorry for my imperfect English.
But let me explain my problem with apache vhosts.



Example:
My servername is example.de (/etc/hostname). If I configure for this specific domain my vhost won´t work. It seems apache uses the default-vhost. But I need the default-vhost for pages that are not active on my server. So I can´t use it for the domain example.de



I need a solution for following problem:




  • example.de - Should point to /var/www/example (This doesn´t work,
    because /etc/hostanme)

  • example2.de - Should point to /var/www/example2
    (This works)

  • domain-i-got-but-not-active.de Should point to
    /var/www/default (This works, but also catches example.de)


I can´t change my hostname, because mails sent from my server will be detect as spam if the server name is not correctly set.



Here is an example of my vhost:



 # For default-pages
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/default
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/default>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

# Doesn´t work, points to default (above code)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example.de
DocumentRoot /var/www/example
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

# All fine
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example2.de
DocumentRoot /var/www/example2
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example2>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>









share|improve this question
























  • That's why we have moderators. Und dein English is nicht "scheissig"! Nur "Imperfekt"
    – Fabby
    Nov 26 '14 at 0:40
















1














First of all, sorry for my imperfect English.
But let me explain my problem with apache vhosts.



Example:
My servername is example.de (/etc/hostname). If I configure for this specific domain my vhost won´t work. It seems apache uses the default-vhost. But I need the default-vhost for pages that are not active on my server. So I can´t use it for the domain example.de



I need a solution for following problem:




  • example.de - Should point to /var/www/example (This doesn´t work,
    because /etc/hostanme)

  • example2.de - Should point to /var/www/example2
    (This works)

  • domain-i-got-but-not-active.de Should point to
    /var/www/default (This works, but also catches example.de)


I can´t change my hostname, because mails sent from my server will be detect as spam if the server name is not correctly set.



Here is an example of my vhost:



 # For default-pages
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/default
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/default>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

# Doesn´t work, points to default (above code)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example.de
DocumentRoot /var/www/example
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

# All fine
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example2.de
DocumentRoot /var/www/example2
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example2>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>









share|improve this question
























  • That's why we have moderators. Und dein English is nicht "scheissig"! Nur "Imperfekt"
    – Fabby
    Nov 26 '14 at 0:40














1












1








1


1





First of all, sorry for my imperfect English.
But let me explain my problem with apache vhosts.



Example:
My servername is example.de (/etc/hostname). If I configure for this specific domain my vhost won´t work. It seems apache uses the default-vhost. But I need the default-vhost for pages that are not active on my server. So I can´t use it for the domain example.de



I need a solution for following problem:




  • example.de - Should point to /var/www/example (This doesn´t work,
    because /etc/hostanme)

  • example2.de - Should point to /var/www/example2
    (This works)

  • domain-i-got-but-not-active.de Should point to
    /var/www/default (This works, but also catches example.de)


I can´t change my hostname, because mails sent from my server will be detect as spam if the server name is not correctly set.



Here is an example of my vhost:



 # For default-pages
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/default
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/default>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

# Doesn´t work, points to default (above code)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example.de
DocumentRoot /var/www/example
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

# All fine
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example2.de
DocumentRoot /var/www/example2
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example2>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>









share|improve this question















First of all, sorry for my imperfect English.
But let me explain my problem with apache vhosts.



Example:
My servername is example.de (/etc/hostname). If I configure for this specific domain my vhost won´t work. It seems apache uses the default-vhost. But I need the default-vhost for pages that are not active on my server. So I can´t use it for the domain example.de



I need a solution for following problem:




  • example.de - Should point to /var/www/example (This doesn´t work,
    because /etc/hostanme)

  • example2.de - Should point to /var/www/example2
    (This works)

  • domain-i-got-but-not-active.de Should point to
    /var/www/default (This works, but also catches example.de)


I can´t change my hostname, because mails sent from my server will be detect as spam if the server name is not correctly set.



Here is an example of my vhost:



 # For default-pages
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/default
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/default>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

# Doesn´t work, points to default (above code)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example.de
DocumentRoot /var/www/example
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

# All fine
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example2.de
DocumentRoot /var/www/example2
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example2>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>






server apache2 hostname






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '14 at 0:37









Fabby

26.5k1360159




26.5k1360159










asked Nov 23 '14 at 21:55









TatzyXY

612




612












  • That's why we have moderators. Und dein English is nicht "scheissig"! Nur "Imperfekt"
    – Fabby
    Nov 26 '14 at 0:40


















  • That's why we have moderators. Und dein English is nicht "scheissig"! Nur "Imperfekt"
    – Fabby
    Nov 26 '14 at 0:40
















That's why we have moderators. Und dein English is nicht "scheissig"! Nur "Imperfekt"
– Fabby
Nov 26 '14 at 0:40




That's why we have moderators. Und dein English is nicht "scheissig"! Nur "Imperfekt"
– Fabby
Nov 26 '14 at 0:40










2 Answers
2






active

oldest

votes


















0














According to Apache documentation:




If no ServerName is specified, then the server attempts to deduce the
hostname by performing a reverse lookup on the IP address.




Reverse lookup: Look up an IP address to find the domain name for the IP address.



I guess that this is why example.de is served by your default VirtualHost, so try to add ServerName domain-i-got-but-not-active.de, and if this VirtualHost is the first defined:




it has the highest priority and can be seen as the default or primary
server. That means that if a request is received that does not match
one of the specified ServerName directives, it will be served by this
first VirtualHost.







share|improve this answer





























    0














    <VirtualHost *:80>
    DocumentRoot /var/www/example
    DirectoryIndex index.php
    ServerName example.de
    setEnv DOMAIN_NAME example.de
    <Directory "/var/www/example">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
    </Directory>
    </VirtualHost>


    try this






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "89"
      };
      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%2faskubuntu.com%2fquestions%2f553019%2fhow-configure-apache-vhost-for-server-hostname%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      According to Apache documentation:




      If no ServerName is specified, then the server attempts to deduce the
      hostname by performing a reverse lookup on the IP address.




      Reverse lookup: Look up an IP address to find the domain name for the IP address.



      I guess that this is why example.de is served by your default VirtualHost, so try to add ServerName domain-i-got-but-not-active.de, and if this VirtualHost is the first defined:




      it has the highest priority and can be seen as the default or primary
      server. That means that if a request is received that does not match
      one of the specified ServerName directives, it will be served by this
      first VirtualHost.







      share|improve this answer


























        0














        According to Apache documentation:




        If no ServerName is specified, then the server attempts to deduce the
        hostname by performing a reverse lookup on the IP address.




        Reverse lookup: Look up an IP address to find the domain name for the IP address.



        I guess that this is why example.de is served by your default VirtualHost, so try to add ServerName domain-i-got-but-not-active.de, and if this VirtualHost is the first defined:




        it has the highest priority and can be seen as the default or primary
        server. That means that if a request is received that does not match
        one of the specified ServerName directives, it will be served by this
        first VirtualHost.







        share|improve this answer
























          0












          0








          0






          According to Apache documentation:




          If no ServerName is specified, then the server attempts to deduce the
          hostname by performing a reverse lookup on the IP address.




          Reverse lookup: Look up an IP address to find the domain name for the IP address.



          I guess that this is why example.de is served by your default VirtualHost, so try to add ServerName domain-i-got-but-not-active.de, and if this VirtualHost is the first defined:




          it has the highest priority and can be seen as the default or primary
          server. That means that if a request is received that does not match
          one of the specified ServerName directives, it will be served by this
          first VirtualHost.







          share|improve this answer












          According to Apache documentation:




          If no ServerName is specified, then the server attempts to deduce the
          hostname by performing a reverse lookup on the IP address.




          Reverse lookup: Look up an IP address to find the domain name for the IP address.



          I guess that this is why example.de is served by your default VirtualHost, so try to add ServerName domain-i-got-but-not-active.de, and if this VirtualHost is the first defined:




          it has the highest priority and can be seen as the default or primary
          server. That means that if a request is received that does not match
          one of the specified ServerName directives, it will be served by this
          first VirtualHost.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '14 at 0:31









          Lety

          4,94521730




          4,94521730

























              0














              <VirtualHost *:80>
              DocumentRoot /var/www/example
              DirectoryIndex index.php
              ServerName example.de
              setEnv DOMAIN_NAME example.de
              <Directory "/var/www/example">
              Options Indexes FollowSymLinks MultiViews
              AllowOverride All
              Order allow,deny
              allow from all
              Require all granted
              </Directory>
              </VirtualHost>


              try this






              share|improve this answer


























                0














                <VirtualHost *:80>
                DocumentRoot /var/www/example
                DirectoryIndex index.php
                ServerName example.de
                setEnv DOMAIN_NAME example.de
                <Directory "/var/www/example">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                Require all granted
                </Directory>
                </VirtualHost>


                try this






                share|improve this answer
























                  0












                  0








                  0






                  <VirtualHost *:80>
                  DocumentRoot /var/www/example
                  DirectoryIndex index.php
                  ServerName example.de
                  setEnv DOMAIN_NAME example.de
                  <Directory "/var/www/example">
                  Options Indexes FollowSymLinks MultiViews
                  AllowOverride All
                  Order allow,deny
                  allow from all
                  Require all granted
                  </Directory>
                  </VirtualHost>


                  try this






                  share|improve this answer












                  <VirtualHost *:80>
                  DocumentRoot /var/www/example
                  DirectoryIndex index.php
                  ServerName example.de
                  setEnv DOMAIN_NAME example.de
                  <Directory "/var/www/example">
                  Options Indexes FollowSymLinks MultiViews
                  AllowOverride All
                  Order allow,deny
                  allow from all
                  Require all granted
                  </Directory>
                  </VirtualHost>


                  try this







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '18 at 20:07









                  GHOST

                  269111




                  269111






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Ask Ubuntu!


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





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2faskubuntu.com%2fquestions%2f553019%2fhow-configure-apache-vhost-for-server-hostname%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

                      Ellipse (mathématiques)

                      Quarter-circle Tiles

                      Mont Emei