PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 21, 2022

[FIXED] How to use two subdomain with Apache?

 September 21, 2022     apache, virtualhost     No comments   

Issue

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


Solution

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>


Answered By - Parth Modi
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing