Question

point new domain to different directory on same droplet in centos 7 x64 using virtualhost

important info: the domain names maindoamin.com and otherdomain.com are for information only, i am working on a real domain name, but for privacy i have used these two domain names here to explain my issue…

i am following this article: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7

i had just bought a droplet which has centos 7 x64 and httpd, php, mysql installed using articles and tutorials at digitalocean and everything is working perfect.

but i want to use more than one domain in my single droplet, which has above stated config, for that i had created a mysite.conf at /etc/httpd/conf.d with below lines of code::

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName www.maindomain.com
    ServerAlias maindomain.com
    DocumentRoot /var/www/html/
    ErrorLog /var/www/html/error.log
    CustomLog /var/www/html/requests.log combined
</VirtualHost>
<VirtualHost *:80>
    ServerName www.otherdomain.com
    ServerAlias otherdomain.com
    DocumentRoot /var/www/html/otherdomain.com
    ErrorLog /var/www/html/otherdomain.com/error.log
    CustomLog /var/www/html/otherdomain.com/requests.log combined
</VirtualHost>

but i getting below when i am restarting httpd service using putty :::

[root@muhammad ~]# sudo service httpd restart
Redirecting to /bin/systemctl restart  httpd.service
Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.

but when i keep only one virtual host ie:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName www.otherdomain.com
    ServerAlias otherdomain.com
    DocumentRoot /var/www/html/otherdomain.com
    ErrorLog /var/www/html/otherdomain.com/error.log
    CustomLog /var/www/html/otherdomain.com/requests.log combined
</VirtualHost>

now httpd restart works… and when i navigate to www.otherdomain.com using web browser, my index file get displayed which i had at my otherdomain.com folder but my maindomain.com also uses the index.html file , but the index.html file is at otherdomain.com folder at /var/www/html/otherdomain.com/index.html, this i understand why it doing this,

but my question is how can i setup it properly so that my maindomain.com uses /var/www/html/ and otherdomain.com uses /var/www/html/otherdomain.com/ , please help thanks in advance…

Subscribe
Share

So to create a directory alias within a domain would you add the folder Alias withing the <VirtualHost *:80> and </VirtualHost> tags?


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

i found the solution… so posting here so that other may get help…

just changed the mysite.conf with below lines:

NameVirtualHost *:80

<VirtualHost maindomain.com:80>
    ServerName www.maindomain.com
    ServerAlias maindomain.com
    DocumentRoot /var/www/html/
    ErrorLog /var/www/html/error.log
    CustomLog /var/www/html/requests.log combined
    <Directory "/var/www/html">
		Options Indexes FollowSymLinks 
		AllowOverride All 
		Order allow,deny 
		Allow from all 
	</Directory> 
</VirtualHost>

<VirtualHost otherdomain.com:80>
    ServerName www.otherdomain.com
    ServerAlias otherdomain.com
    DocumentRoot /var/www/html/otherdomain.com
    ErrorLog /var/www/html/otherdomain.com/error.log
    CustomLog /var/www/html/otherdomain.com/requests.log combined
    <Directory "/var/www/html/otherdomain.com">
		Options Indexes FollowSymLinks 
		AllowOverride All 
		Order allow,deny 
		Allow from all 
	</Directory> 
</VirtualHost>