how to setup subdomains

Sorry but I couldn't find any help on other topics.

I am a newby owning a linode and would like to know how to setup subdomains.

Having my main domain, http://example.com, properly running I added an entry in the A records like subdomain (linode dns manager).

The idea is to get http://subdomain.example.com showing a different site than the one presented with http://example.com

I setted up a couple of virtual servers in apache2 pointing to the destination directories pending on the NameVirtualHost directive.

Now the issue is that I get the same contents (the subdomain ones) both directing the browser to the main and the subdomain sites…

what am I doing wrong?

thanks a lot in advance to anyone helping me!

8 Replies

Did you restart apache after adding the vhosts?

@dolphin:

yes Sir!

Can you paste in your vhost config?

@dolphin:

how do I get it?

:roll: @dolphin:

I setted up a couple of virtual servers in apache2 pointing to the destination directories pending on the NameVirtualHost directive.

You said you already set up the vhosts. Just copy/paste that…

sorry,

default

NameVirtualHost *
 <virtualhost *="">ServerAdmin webmaster@localhost
        ServerName grandolini.info
        ServerAlias www.grandolini.info

DocumentRoot /home/www
        <directory>Options FollowSymLinks
                AllowOverride None</directory> 
        <directory home="" www="">Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                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 /home/www/log/apache2-error.log

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

        CustomLog /home/www/log/apache2-access.log combined
        ServerSignature On

    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> 

subdomain

NameVirtualHost progesoft.grandolini.info
 <virtualhost progesoft.grandolini.info="">ServerAdmin ugo@progesoft.com
        ServerName progesoft.grandolini.info
        ServerAlias www.progesoft.grandolini.info

DocumentRoot /home/www/progeSOFT
        <directory>Options FollowSymLinks
                AllowOverride None</directory> 
        <directory home="" www="" progesoft="">Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                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 /home/www/log/progeSOFT/apache2-error.log

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

        CustomLog /home/www/log/progeSOFT/apache2-access.log combined
        ServerSignature On

    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> 

thanks a lot!

@dolphin:

NameVirtualHost progesoft.grandolini.info
<virtualhost progesoft.grandolini.info=""></virtualhost>


That just might be your problem, then. From what I understand from the Apache manual, NameVirtualHost needs to be an IP address or an IP adress with a port specification (either can be just a "*" to denote all possibilities).

Since you've already used "NameVirtualHost *" in the default file, you don't need to set it again. Just do it like this for your subdomain:

 <virtualhost *="">ServerAdmin ugo@progesoft.com 
        ServerName progesoft.grandolini.info 
        ServerAlias www.progesoft.grandolini.info 

DocumentRoot /home/www/progeSOFT 
        <directory> 
                Options FollowSymLinks 
                AllowOverride None 
        </directory> 
        <directory home="" www="" progesoft=""> 
                Options Indexes FollowSymLinks MultiViews 
                AllowOverride None 
                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 /home/www/log/progeSOFT/apache2-error.log 

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

        CustomLog /home/www/log/progeSOFT/apache2-access.log combined 
        ServerSignature On 

    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> 

YEEEE :D

it works!!

THANKS A LOT NEONNERO!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

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

> I’m a blockquote.

I’m a blockquote.

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

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct