jevin kaneriya
jevin kaneriya

Reputation: 135

How to use two subdomain with Apache?

I have domain on name.com and I created two subdomain from DNS record

Type, Host,                   Answer,               TTL
A,    subdomain1.domain.com , EC2 IP,               300
A,    subdomain2.domain.com , EC2 IP same as above, 300


<VirtualHost *:80>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ServerName subdmain1.domain.com
        ServerAlias www.subdmain1.domain.com

        Project related Configuration....

</VirtualHost>
<VirtualHost *:80>
        ServerName subdomain2.domain.com
        ServerAlias www.subdomain2.domain.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        Second project code ....
</VirtualHost>

I did above configuration in apache2 of my EC2 server but When I access any subdomain that automatic always goes to first VirtualHost and second Virtualhost not working.

please Help me for configure both subdomain on ec2

Note: I'm using main domain.com on name.com website

Upvotes: 0

Views: 54

Answers (1)

Parth Modi
Parth Modi

Reputation: 291

May be you should remove '*' from virtualhost and provide respactive domain name and add domain name in your allowedhost in respactive settings file, it worked for me.

<VirtualHost subdmain1.domain.com:80>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ServerName subdmain1.domain.com
    ServerAlias www.subdmain1.domain.com
    Project related Configuration....
</VirtualHost>

and

<VirtualHost subdomain2.domain.com:80>
    ServerName subdomain2.domain.com
    ServerAlias www.subdomain2.domain.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    Second project code ...
</VirtualHost>

Upvotes: 2

Related Questions