ServerAlias not working The Next CEO of Stack OverflowApache always serving first virtual...

How to Reset Passwords on Multiple Websites Easily?

What is the difference between "behavior" and "behaviour"?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Natural language into sentence logic

How to safely derail a train during transit?

If I blow insulation everywhere in my attic except the door trap, will heat escape through it?

Is HostGator storing my password in plaintext?

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

How do we know the LHC results are robust?

Is it safe to use c_str() on a temporary string?

What happens if you roll doubles 3 times then land on "Go to jail?"

Is it okay to store user locations?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How does practicing restraint and performing actions of merit purify the mind?

WOW air has ceased operation, can I get my tickets refunded?

Why do professional authors make "consistency" mistakes? And how to avoid them?

Is a stroke of luck acceptable after a series of unfavorable events?

Increase performance creating Mandelbrot set in python

Robert Sheckley short story about vacation spots being overwhelmed

How do I go from 300 unfinished/half written blog posts, to published posts?

Should I tutor a student who I know has cheated on their homework?

What can we do to stop prior company from asking us questions?

How to write papers efficiently when English isn't my first language?

Opposite of a diet



ServerAlias not working



The Next CEO of Stack OverflowApache always serving first virtual hostapache deny directive not workingApache2 Permission denied: access to / deniedapache2 configuration for blog.example.com not workingApache Virtual Hosts Not WorkingSubdomain not being recognised in sites-availableLive site with ssl enabled redirects to the staging site without sslAdding additional host to Apache2Virtual hosts with port 80 & 443 not workingServerAlias without www not working on SSL virtualhostServer redirecting to root vhost file












2















I have a VPS, that I have configured to host multiple websites with name based hosting. It is all good while only using example.com, and www.example.com. It also works with example.net, but when I try example.net, it reverts to my default site configuration, which just shows my default (empty) index.html page.



Here's the default file:



<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>


Here's a configuration for the example.com site:



    <VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
<Directory /srv/www/example.com/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


And here is the config for the example.net site:



<VirtualHost *:80>
ServerAdmin admin@example.net
ServerName example.net
ServerAlias www.example.net
DocumentRoot /srv/www/example.net/public_html/
ErrorLog /srv/www/example.net/logs/error.log
CustomLog /srv/www/example.net/logs/access.log combined
<Directory /srv/www/example.net/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


Where could the problem be?



I believe, that there is something going wrong with the ServerAlias property.



Could it be because of the way the site's are built? Because example.com is a Joomla site, and example.net is a Zend Framework site. Just in case, I'll also insert the .htaccess files for example.net, since example.com has it's disabled:
example.net:



SetEnv APPLICATION_ENV development

RewriteRule ^(browse|config).* - [L]
ErrorDocument 500 /error-docs/500.shtml
SetEnv CACHE_OFFSET 2678400


<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Fri, 25 Sep 2037 19:30:32 GMT"
Header unset ETag
FileETag None
</FilesMatch>

RewriteEngine On
RewriteRule ^(adm|statistics) - [L]
RewriteRule ^/public/(.*)$ http://example.net/$1 [R]
RewriteRule ^(.*)$ public/$1 [L]


Any help would be greatly appreciated!



Edit So that my question is ABSOLUTELY clear:
The problem is, that one site works with both www prefix as well as without it, and the second one does not. I would like to know how to enable the second site to work with www prefix as well.










share|improve this question

























  • Did you restart apache? What do the error_log and access_log say?

    – dmah
    Dec 13 '10 at 16:12











  • Your question contains a real emailaddress as well as a domain. You'd better remove it. Please avoid using example2.com and use example.com, example.net or example.org instead. How did you include your configuration files?

    – Lekensteyn
    Dec 13 '10 at 16:45













  • Sorry, wasn't intentional, fixed! Since I'm using an Ubuntu server, I included them with a2ensite example.net;a2ensite example.com . Did a server restart after that

    – Janis Peisenieks
    Dec 13 '10 at 17:08
















2















I have a VPS, that I have configured to host multiple websites with name based hosting. It is all good while only using example.com, and www.example.com. It also works with example.net, but when I try example.net, it reverts to my default site configuration, which just shows my default (empty) index.html page.



Here's the default file:



<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>


Here's a configuration for the example.com site:



    <VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
<Directory /srv/www/example.com/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


And here is the config for the example.net site:



<VirtualHost *:80>
ServerAdmin admin@example.net
ServerName example.net
ServerAlias www.example.net
DocumentRoot /srv/www/example.net/public_html/
ErrorLog /srv/www/example.net/logs/error.log
CustomLog /srv/www/example.net/logs/access.log combined
<Directory /srv/www/example.net/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


Where could the problem be?



I believe, that there is something going wrong with the ServerAlias property.



Could it be because of the way the site's are built? Because example.com is a Joomla site, and example.net is a Zend Framework site. Just in case, I'll also insert the .htaccess files for example.net, since example.com has it's disabled:
example.net:



SetEnv APPLICATION_ENV development

RewriteRule ^(browse|config).* - [L]
ErrorDocument 500 /error-docs/500.shtml
SetEnv CACHE_OFFSET 2678400


<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Fri, 25 Sep 2037 19:30:32 GMT"
Header unset ETag
FileETag None
</FilesMatch>

RewriteEngine On
RewriteRule ^(adm|statistics) - [L]
RewriteRule ^/public/(.*)$ http://example.net/$1 [R]
RewriteRule ^(.*)$ public/$1 [L]


Any help would be greatly appreciated!



Edit So that my question is ABSOLUTELY clear:
The problem is, that one site works with both www prefix as well as without it, and the second one does not. I would like to know how to enable the second site to work with www prefix as well.










share|improve this question

























  • Did you restart apache? What do the error_log and access_log say?

    – dmah
    Dec 13 '10 at 16:12











  • Your question contains a real emailaddress as well as a domain. You'd better remove it. Please avoid using example2.com and use example.com, example.net or example.org instead. How did you include your configuration files?

    – Lekensteyn
    Dec 13 '10 at 16:45













  • Sorry, wasn't intentional, fixed! Since I'm using an Ubuntu server, I included them with a2ensite example.net;a2ensite example.com . Did a server restart after that

    – Janis Peisenieks
    Dec 13 '10 at 17:08














2












2








2


1






I have a VPS, that I have configured to host multiple websites with name based hosting. It is all good while only using example.com, and www.example.com. It also works with example.net, but when I try example.net, it reverts to my default site configuration, which just shows my default (empty) index.html page.



Here's the default file:



<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>


Here's a configuration for the example.com site:



    <VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
<Directory /srv/www/example.com/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


And here is the config for the example.net site:



<VirtualHost *:80>
ServerAdmin admin@example.net
ServerName example.net
ServerAlias www.example.net
DocumentRoot /srv/www/example.net/public_html/
ErrorLog /srv/www/example.net/logs/error.log
CustomLog /srv/www/example.net/logs/access.log combined
<Directory /srv/www/example.net/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


Where could the problem be?



I believe, that there is something going wrong with the ServerAlias property.



Could it be because of the way the site's are built? Because example.com is a Joomla site, and example.net is a Zend Framework site. Just in case, I'll also insert the .htaccess files for example.net, since example.com has it's disabled:
example.net:



SetEnv APPLICATION_ENV development

RewriteRule ^(browse|config).* - [L]
ErrorDocument 500 /error-docs/500.shtml
SetEnv CACHE_OFFSET 2678400


<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Fri, 25 Sep 2037 19:30:32 GMT"
Header unset ETag
FileETag None
</FilesMatch>

RewriteEngine On
RewriteRule ^(adm|statistics) - [L]
RewriteRule ^/public/(.*)$ http://example.net/$1 [R]
RewriteRule ^(.*)$ public/$1 [L]


Any help would be greatly appreciated!



Edit So that my question is ABSOLUTELY clear:
The problem is, that one site works with both www prefix as well as without it, and the second one does not. I would like to know how to enable the second site to work with www prefix as well.










share|improve this question
















I have a VPS, that I have configured to host multiple websites with name based hosting. It is all good while only using example.com, and www.example.com. It also works with example.net, but when I try example.net, it reverts to my default site configuration, which just shows my default (empty) index.html page.



Here's the default file:



<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>


Here's a configuration for the example.com site:



    <VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
<Directory /srv/www/example.com/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


And here is the config for the example.net site:



<VirtualHost *:80>
ServerAdmin admin@example.net
ServerName example.net
ServerAlias www.example.net
DocumentRoot /srv/www/example.net/public_html/
ErrorLog /srv/www/example.net/logs/error.log
CustomLog /srv/www/example.net/logs/access.log combined
<Directory /srv/www/example.net/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


Where could the problem be?



I believe, that there is something going wrong with the ServerAlias property.



Could it be because of the way the site's are built? Because example.com is a Joomla site, and example.net is a Zend Framework site. Just in case, I'll also insert the .htaccess files for example.net, since example.com has it's disabled:
example.net:



SetEnv APPLICATION_ENV development

RewriteRule ^(browse|config).* - [L]
ErrorDocument 500 /error-docs/500.shtml
SetEnv CACHE_OFFSET 2678400


<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Fri, 25 Sep 2037 19:30:32 GMT"
Header unset ETag
FileETag None
</FilesMatch>

RewriteEngine On
RewriteRule ^(adm|statistics) - [L]
RewriteRule ^/public/(.*)$ http://example.net/$1 [R]
RewriteRule ^(.*)$ public/$1 [L]


Any help would be greatly appreciated!



Edit So that my question is ABSOLUTELY clear:
The problem is, that one site works with both www prefix as well as without it, and the second one does not. I would like to know how to enable the second site to work with www prefix as well.







apache-2.2 .htaccess virtualhost serveralias






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 13 '10 at 17:07







Janis Peisenieks

















asked Dec 13 '10 at 16:09









Janis PeisenieksJanis Peisenieks

1741411




1741411













  • Did you restart apache? What do the error_log and access_log say?

    – dmah
    Dec 13 '10 at 16:12











  • Your question contains a real emailaddress as well as a domain. You'd better remove it. Please avoid using example2.com and use example.com, example.net or example.org instead. How did you include your configuration files?

    – Lekensteyn
    Dec 13 '10 at 16:45













  • Sorry, wasn't intentional, fixed! Since I'm using an Ubuntu server, I included them with a2ensite example.net;a2ensite example.com . Did a server restart after that

    – Janis Peisenieks
    Dec 13 '10 at 17:08



















  • Did you restart apache? What do the error_log and access_log say?

    – dmah
    Dec 13 '10 at 16:12











  • Your question contains a real emailaddress as well as a domain. You'd better remove it. Please avoid using example2.com and use example.com, example.net or example.org instead. How did you include your configuration files?

    – Lekensteyn
    Dec 13 '10 at 16:45













  • Sorry, wasn't intentional, fixed! Since I'm using an Ubuntu server, I included them with a2ensite example.net;a2ensite example.com . Did a server restart after that

    – Janis Peisenieks
    Dec 13 '10 at 17:08

















Did you restart apache? What do the error_log and access_log say?

– dmah
Dec 13 '10 at 16:12





Did you restart apache? What do the error_log and access_log say?

– dmah
Dec 13 '10 at 16:12













Your question contains a real emailaddress as well as a domain. You'd better remove it. Please avoid using example2.com and use example.com, example.net or example.org instead. How did you include your configuration files?

– Lekensteyn
Dec 13 '10 at 16:45







Your question contains a real emailaddress as well as a domain. You'd better remove it. Please avoid using example2.com and use example.com, example.net or example.org instead. How did you include your configuration files?

– Lekensteyn
Dec 13 '10 at 16:45















Sorry, wasn't intentional, fixed! Since I'm using an Ubuntu server, I included them with a2ensite example.net;a2ensite example.com . Did a server restart after that

– Janis Peisenieks
Dec 13 '10 at 17:08





Sorry, wasn't intentional, fixed! Since I'm using an Ubuntu server, I included them with a2ensite example.net;a2ensite example.com . Did a server restart after that

– Janis Peisenieks
Dec 13 '10 at 17:08










4 Answers
4






active

oldest

votes


















3














Make sure that the order of precedence in configuration directives matches how Apache should handle the request - i.e. you won't have much luck if your directives load like this:




  • example.com

  • default/catch-all

  • universal.lv


Doesn't matter whether they are declared in a single file or multiple files - so long as "universal.lv" is last, it will not be reached because the default/catch-all vhost will precede it.



I usually name my default/catch-all config "z-default.conf" (or, if you have a domain that starts with a "z", "zz" ... etc) for this reason, to ensure that it is processed only if no other vhost matches.



Try renaming accordingly.





Updated: So as not to confuse w/the _default_ VirtualHost directive



Using wildcard DNS to direct all requests to example.com to the server's IP (catches mis-keyed subdomains), Apache parses the following configuration files:




  • 000-default.conf - VirtualHost _default_:80 / ServerName <hostname> - catch requests against the server's IP (can redirect to primary domain or simply block with the default Directory specified in conf.d/security)

  • example.conf - VirtualHost *:80 / ServerName www.example.com

  • example2.conf - VirtualHost *:80 / ServerName www.example2.com

  • zzz-example.conf - VirtualHost *:80 / ServerName example.com / ServerAlias *.example.com - redirects to canonical www domain

  • zzz-example2.conf - VirtualHost *:80 / ServerName example2.com / ServerAlias *.example2.com - redirects to canonical www domain


As documented, Apache selects the first matching VirtualHost (i.e. _default_:80) but this behavior is not desirable if you are using a wildcard in a ServerAlias directive.






share|improve this answer


























  • Oh, ok, so the precedence is measured by the name of the file? I didn't know this. Will try in a sec.

    – Janis Peisenieks
    Dec 13 '10 at 17:21











  • So, this is the right answer. Thanks for showing me the way precedence works on Ubuntu with Apache2, I knew that there was something like this while I was working on Windows, but thought, that there is some clever mechanism in place on Linux, that took care of this by itself. Thanks, helped!

    – Janis Peisenieks
    Dec 13 '10 at 17:25



















1














I recommend you to read the Apache documentation on Virtual Hosts first.



An excellent example has been given on http://httpd.apache.org/docs/2.2/vhosts/name-based.html:



NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>


Note the NameVirtualHost part. Your error log (/var/log/apache2/error.log) should have warned you that you've made a possible mistake.



Note: after a change to the configuration file, Apache needs to be restarted.






share|improve this answer
























  • Nope, there are no errors in the log file. So practically, I should have made my serverName with the www and have used the *. wildcard and the prefix-less domain name with the ServerAlias?

    – Janis Peisenieks
    Dec 13 '10 at 17:03





















0














you need to have NameVirtualHost enabled into httpd.conf - then you can define multiple virtual host on the same ip:port.






share|improve this answer
























  • This has been done, and is not the issue. I have restated and clarified my problem!

    – Janis Peisenieks
    Dec 13 '10 at 16:41



















0














In my case it was because I copied the files and changed everything except ServerName was the same as my other, so the 2nd was redirecting to the first






share|improve this answer








New contributor




DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















    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%2f212071%2fserveralias-not-working%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Make sure that the order of precedence in configuration directives matches how Apache should handle the request - i.e. you won't have much luck if your directives load like this:




    • example.com

    • default/catch-all

    • universal.lv


    Doesn't matter whether they are declared in a single file or multiple files - so long as "universal.lv" is last, it will not be reached because the default/catch-all vhost will precede it.



    I usually name my default/catch-all config "z-default.conf" (or, if you have a domain that starts with a "z", "zz" ... etc) for this reason, to ensure that it is processed only if no other vhost matches.



    Try renaming accordingly.





    Updated: So as not to confuse w/the _default_ VirtualHost directive



    Using wildcard DNS to direct all requests to example.com to the server's IP (catches mis-keyed subdomains), Apache parses the following configuration files:




    • 000-default.conf - VirtualHost _default_:80 / ServerName <hostname> - catch requests against the server's IP (can redirect to primary domain or simply block with the default Directory specified in conf.d/security)

    • example.conf - VirtualHost *:80 / ServerName www.example.com

    • example2.conf - VirtualHost *:80 / ServerName www.example2.com

    • zzz-example.conf - VirtualHost *:80 / ServerName example.com / ServerAlias *.example.com - redirects to canonical www domain

    • zzz-example2.conf - VirtualHost *:80 / ServerName example2.com / ServerAlias *.example2.com - redirects to canonical www domain


    As documented, Apache selects the first matching VirtualHost (i.e. _default_:80) but this behavior is not desirable if you are using a wildcard in a ServerAlias directive.






    share|improve this answer


























    • Oh, ok, so the precedence is measured by the name of the file? I didn't know this. Will try in a sec.

      – Janis Peisenieks
      Dec 13 '10 at 17:21











    • So, this is the right answer. Thanks for showing me the way precedence works on Ubuntu with Apache2, I knew that there was something like this while I was working on Windows, but thought, that there is some clever mechanism in place on Linux, that took care of this by itself. Thanks, helped!

      – Janis Peisenieks
      Dec 13 '10 at 17:25
















    3














    Make sure that the order of precedence in configuration directives matches how Apache should handle the request - i.e. you won't have much luck if your directives load like this:




    • example.com

    • default/catch-all

    • universal.lv


    Doesn't matter whether they are declared in a single file or multiple files - so long as "universal.lv" is last, it will not be reached because the default/catch-all vhost will precede it.



    I usually name my default/catch-all config "z-default.conf" (or, if you have a domain that starts with a "z", "zz" ... etc) for this reason, to ensure that it is processed only if no other vhost matches.



    Try renaming accordingly.





    Updated: So as not to confuse w/the _default_ VirtualHost directive



    Using wildcard DNS to direct all requests to example.com to the server's IP (catches mis-keyed subdomains), Apache parses the following configuration files:




    • 000-default.conf - VirtualHost _default_:80 / ServerName <hostname> - catch requests against the server's IP (can redirect to primary domain or simply block with the default Directory specified in conf.d/security)

    • example.conf - VirtualHost *:80 / ServerName www.example.com

    • example2.conf - VirtualHost *:80 / ServerName www.example2.com

    • zzz-example.conf - VirtualHost *:80 / ServerName example.com / ServerAlias *.example.com - redirects to canonical www domain

    • zzz-example2.conf - VirtualHost *:80 / ServerName example2.com / ServerAlias *.example2.com - redirects to canonical www domain


    As documented, Apache selects the first matching VirtualHost (i.e. _default_:80) but this behavior is not desirable if you are using a wildcard in a ServerAlias directive.






    share|improve this answer


























    • Oh, ok, so the precedence is measured by the name of the file? I didn't know this. Will try in a sec.

      – Janis Peisenieks
      Dec 13 '10 at 17:21











    • So, this is the right answer. Thanks for showing me the way precedence works on Ubuntu with Apache2, I knew that there was something like this while I was working on Windows, but thought, that there is some clever mechanism in place on Linux, that took care of this by itself. Thanks, helped!

      – Janis Peisenieks
      Dec 13 '10 at 17:25














    3












    3








    3







    Make sure that the order of precedence in configuration directives matches how Apache should handle the request - i.e. you won't have much luck if your directives load like this:




    • example.com

    • default/catch-all

    • universal.lv


    Doesn't matter whether they are declared in a single file or multiple files - so long as "universal.lv" is last, it will not be reached because the default/catch-all vhost will precede it.



    I usually name my default/catch-all config "z-default.conf" (or, if you have a domain that starts with a "z", "zz" ... etc) for this reason, to ensure that it is processed only if no other vhost matches.



    Try renaming accordingly.





    Updated: So as not to confuse w/the _default_ VirtualHost directive



    Using wildcard DNS to direct all requests to example.com to the server's IP (catches mis-keyed subdomains), Apache parses the following configuration files:




    • 000-default.conf - VirtualHost _default_:80 / ServerName <hostname> - catch requests against the server's IP (can redirect to primary domain or simply block with the default Directory specified in conf.d/security)

    • example.conf - VirtualHost *:80 / ServerName www.example.com

    • example2.conf - VirtualHost *:80 / ServerName www.example2.com

    • zzz-example.conf - VirtualHost *:80 / ServerName example.com / ServerAlias *.example.com - redirects to canonical www domain

    • zzz-example2.conf - VirtualHost *:80 / ServerName example2.com / ServerAlias *.example2.com - redirects to canonical www domain


    As documented, Apache selects the first matching VirtualHost (i.e. _default_:80) but this behavior is not desirable if you are using a wildcard in a ServerAlias directive.






    share|improve this answer















    Make sure that the order of precedence in configuration directives matches how Apache should handle the request - i.e. you won't have much luck if your directives load like this:




    • example.com

    • default/catch-all

    • universal.lv


    Doesn't matter whether they are declared in a single file or multiple files - so long as "universal.lv" is last, it will not be reached because the default/catch-all vhost will precede it.



    I usually name my default/catch-all config "z-default.conf" (or, if you have a domain that starts with a "z", "zz" ... etc) for this reason, to ensure that it is processed only if no other vhost matches.



    Try renaming accordingly.





    Updated: So as not to confuse w/the _default_ VirtualHost directive



    Using wildcard DNS to direct all requests to example.com to the server's IP (catches mis-keyed subdomains), Apache parses the following configuration files:




    • 000-default.conf - VirtualHost _default_:80 / ServerName <hostname> - catch requests against the server's IP (can redirect to primary domain or simply block with the default Directory specified in conf.d/security)

    • example.conf - VirtualHost *:80 / ServerName www.example.com

    • example2.conf - VirtualHost *:80 / ServerName www.example2.com

    • zzz-example.conf - VirtualHost *:80 / ServerName example.com / ServerAlias *.example.com - redirects to canonical www domain

    • zzz-example2.conf - VirtualHost *:80 / ServerName example2.com / ServerAlias *.example2.com - redirects to canonical www domain


    As documented, Apache selects the first matching VirtualHost (i.e. _default_:80) but this behavior is not desirable if you are using a wildcard in a ServerAlias directive.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 22 '10 at 15:47

























    answered Dec 13 '10 at 17:15









    danlefreedanlefree

    2,75111418




    2,75111418













    • Oh, ok, so the precedence is measured by the name of the file? I didn't know this. Will try in a sec.

      – Janis Peisenieks
      Dec 13 '10 at 17:21











    • So, this is the right answer. Thanks for showing me the way precedence works on Ubuntu with Apache2, I knew that there was something like this while I was working on Windows, but thought, that there is some clever mechanism in place on Linux, that took care of this by itself. Thanks, helped!

      – Janis Peisenieks
      Dec 13 '10 at 17:25



















    • Oh, ok, so the precedence is measured by the name of the file? I didn't know this. Will try in a sec.

      – Janis Peisenieks
      Dec 13 '10 at 17:21











    • So, this is the right answer. Thanks for showing me the way precedence works on Ubuntu with Apache2, I knew that there was something like this while I was working on Windows, but thought, that there is some clever mechanism in place on Linux, that took care of this by itself. Thanks, helped!

      – Janis Peisenieks
      Dec 13 '10 at 17:25

















    Oh, ok, so the precedence is measured by the name of the file? I didn't know this. Will try in a sec.

    – Janis Peisenieks
    Dec 13 '10 at 17:21





    Oh, ok, so the precedence is measured by the name of the file? I didn't know this. Will try in a sec.

    – Janis Peisenieks
    Dec 13 '10 at 17:21













    So, this is the right answer. Thanks for showing me the way precedence works on Ubuntu with Apache2, I knew that there was something like this while I was working on Windows, but thought, that there is some clever mechanism in place on Linux, that took care of this by itself. Thanks, helped!

    – Janis Peisenieks
    Dec 13 '10 at 17:25





    So, this is the right answer. Thanks for showing me the way precedence works on Ubuntu with Apache2, I knew that there was something like this while I was working on Windows, but thought, that there is some clever mechanism in place on Linux, that took care of this by itself. Thanks, helped!

    – Janis Peisenieks
    Dec 13 '10 at 17:25













    1














    I recommend you to read the Apache documentation on Virtual Hosts first.



    An excellent example has been given on http://httpd.apache.org/docs/2.2/vhosts/name-based.html:



    NameVirtualHost *:80

    <VirtualHost *:80>
    ServerName www.domain.tld
    ServerAlias domain.tld *.domain.tld
    DocumentRoot /www/domain
    </VirtualHost>

    <VirtualHost *:80>
    ServerName www.otherdomain.tld
    DocumentRoot /www/otherdomain
    </VirtualHost>


    Note the NameVirtualHost part. Your error log (/var/log/apache2/error.log) should have warned you that you've made a possible mistake.



    Note: after a change to the configuration file, Apache needs to be restarted.






    share|improve this answer
























    • Nope, there are no errors in the log file. So practically, I should have made my serverName with the www and have used the *. wildcard and the prefix-less domain name with the ServerAlias?

      – Janis Peisenieks
      Dec 13 '10 at 17:03


















    1














    I recommend you to read the Apache documentation on Virtual Hosts first.



    An excellent example has been given on http://httpd.apache.org/docs/2.2/vhosts/name-based.html:



    NameVirtualHost *:80

    <VirtualHost *:80>
    ServerName www.domain.tld
    ServerAlias domain.tld *.domain.tld
    DocumentRoot /www/domain
    </VirtualHost>

    <VirtualHost *:80>
    ServerName www.otherdomain.tld
    DocumentRoot /www/otherdomain
    </VirtualHost>


    Note the NameVirtualHost part. Your error log (/var/log/apache2/error.log) should have warned you that you've made a possible mistake.



    Note: after a change to the configuration file, Apache needs to be restarted.






    share|improve this answer
























    • Nope, there are no errors in the log file. So practically, I should have made my serverName with the www and have used the *. wildcard and the prefix-less domain name with the ServerAlias?

      – Janis Peisenieks
      Dec 13 '10 at 17:03
















    1












    1








    1







    I recommend you to read the Apache documentation on Virtual Hosts first.



    An excellent example has been given on http://httpd.apache.org/docs/2.2/vhosts/name-based.html:



    NameVirtualHost *:80

    <VirtualHost *:80>
    ServerName www.domain.tld
    ServerAlias domain.tld *.domain.tld
    DocumentRoot /www/domain
    </VirtualHost>

    <VirtualHost *:80>
    ServerName www.otherdomain.tld
    DocumentRoot /www/otherdomain
    </VirtualHost>


    Note the NameVirtualHost part. Your error log (/var/log/apache2/error.log) should have warned you that you've made a possible mistake.



    Note: after a change to the configuration file, Apache needs to be restarted.






    share|improve this answer













    I recommend you to read the Apache documentation on Virtual Hosts first.



    An excellent example has been given on http://httpd.apache.org/docs/2.2/vhosts/name-based.html:



    NameVirtualHost *:80

    <VirtualHost *:80>
    ServerName www.domain.tld
    ServerAlias domain.tld *.domain.tld
    DocumentRoot /www/domain
    </VirtualHost>

    <VirtualHost *:80>
    ServerName www.otherdomain.tld
    DocumentRoot /www/otherdomain
    </VirtualHost>


    Note the NameVirtualHost part. Your error log (/var/log/apache2/error.log) should have warned you that you've made a possible mistake.



    Note: after a change to the configuration file, Apache needs to be restarted.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 13 '10 at 16:43









    LekensteynLekensteyn

    4,62252749




    4,62252749













    • Nope, there are no errors in the log file. So practically, I should have made my serverName with the www and have used the *. wildcard and the prefix-less domain name with the ServerAlias?

      – Janis Peisenieks
      Dec 13 '10 at 17:03





















    • Nope, there are no errors in the log file. So practically, I should have made my serverName with the www and have used the *. wildcard and the prefix-less domain name with the ServerAlias?

      – Janis Peisenieks
      Dec 13 '10 at 17:03



















    Nope, there are no errors in the log file. So practically, I should have made my serverName with the www and have used the *. wildcard and the prefix-less domain name with the ServerAlias?

    – Janis Peisenieks
    Dec 13 '10 at 17:03







    Nope, there are no errors in the log file. So practically, I should have made my serverName with the www and have used the *. wildcard and the prefix-less domain name with the ServerAlias?

    – Janis Peisenieks
    Dec 13 '10 at 17:03













    0














    you need to have NameVirtualHost enabled into httpd.conf - then you can define multiple virtual host on the same ip:port.






    share|improve this answer
























    • This has been done, and is not the issue. I have restated and clarified my problem!

      – Janis Peisenieks
      Dec 13 '10 at 16:41
















    0














    you need to have NameVirtualHost enabled into httpd.conf - then you can define multiple virtual host on the same ip:port.






    share|improve this answer
























    • This has been done, and is not the issue. I have restated and clarified my problem!

      – Janis Peisenieks
      Dec 13 '10 at 16:41














    0












    0








    0







    you need to have NameVirtualHost enabled into httpd.conf - then you can define multiple virtual host on the same ip:port.






    share|improve this answer













    you need to have NameVirtualHost enabled into httpd.conf - then you can define multiple virtual host on the same ip:port.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 13 '10 at 16:22









    silviudsilviud

    2,36421315




    2,36421315













    • This has been done, and is not the issue. I have restated and clarified my problem!

      – Janis Peisenieks
      Dec 13 '10 at 16:41



















    • This has been done, and is not the issue. I have restated and clarified my problem!

      – Janis Peisenieks
      Dec 13 '10 at 16:41

















    This has been done, and is not the issue. I have restated and clarified my problem!

    – Janis Peisenieks
    Dec 13 '10 at 16:41





    This has been done, and is not the issue. I have restated and clarified my problem!

    – Janis Peisenieks
    Dec 13 '10 at 16:41











    0














    In my case it was because I copied the files and changed everything except ServerName was the same as my other, so the 2nd was redirecting to the first






    share|improve this answer








    New contributor




    DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

























      0














      In my case it was because I copied the files and changed everything except ServerName was the same as my other, so the 2nd was redirecting to the first






      share|improve this answer








      New contributor




      DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.























        0












        0








        0







        In my case it was because I copied the files and changed everything except ServerName was the same as my other, so the 2nd was redirecting to the first






        share|improve this answer








        New contributor




        DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        In my case it was because I copied the files and changed everything except ServerName was the same as my other, so the 2nd was redirecting to the first







        share|improve this answer








        New contributor




        DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 10 mins ago









        DWilsDWils

        1011




        1011




        New contributor




        DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        DWils is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























            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%2f212071%2fserveralias-not-working%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

            As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

            Список ссавців Італії Природоохоронні статуси | Список |...

            Українські прізвища Зміст Історичні відомості |...