Apache 2 - Forward different domains in their own folder

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
Hey, in this post im gonna explain, how to forward 2 domains (in this case forum.mydomain.us and download.mydomain.us) into different folders (in this case /var/www/forum/ and /var/www/download). This will only work if you use an Apache server as your webserver.

First you should connect to your server through putty. Now you should install an editor. I'm gonna use nano. To install it, type:
apt-get install nano
Now we create a new virtual host. I'll name it forum because my domain is forum.mydomain.us.
nano /etc/apache2/sites-available/forum.conf
Now type the following in your .conf
<VirtualHost *:80>
ServerName forum.mydomain.us
DocumentRoot /var/www/forum/
<Directory /var/www/foum/>
Options FollowSymLinks MulitViews
AllowOverride All
</Directory>
Now, we create a second host and name it download.conf. We add the same stuff as in the forum.conf, but we have to change some things like the DocumentRoot etc.
nano /etc/apache2/sites-available/download.conf
<VirtualHost *:80>
ServerName download.mydomain.us
DocumentRoot /var/www/download/
<Directory /var/www/download/>
Options FollowSymLinks MulitViews
AllowOverride All
</Directory>
If you done this, you have to enable the .conf's and restart your apache server
a2ensite forum.conf
a2ensite download.conf
/etc/init.d/apache2 reload
If you made everything right, it should work now :) If there are still any questions, feel free to ask me.

Sorry for my english, im german :)
 

Shield

Member
Dec 8, 2015
125
14
53
Hey, in this post im gonna explain, how to forward 2 domains (in this case forum.mydomain.us and download.mydomain.us) into different folders (in this case /var/www/forum/ and /var/www/download). This will only work if you use an Apache server as your webserver.

First you should connect to your server through putty. Now you should install an editor. I'm gonna use nano. To install it, type:

Now we create a new virtual host. I'll name it forum because my domain is forum.mydomain.us.

Now type the following in your .conf

Now, we create a second host and name it download.conf. We add the same stuff as in the forum.conf, but we have to change some things like the DocumentRoot etc.


If you done this, you have to enable the .conf's and restart your apache server



If you made everything right, it should work now :) If there are still any questions, feel free to ask me.

Sorry for my english, im german :)

root@BBTZ003:/var/www# sudo service apache2 reload
* Reloading web server apache2 *
* The apache2 configtest failed. Not doing anything.
Output of config test was:
apache2: Syntax error on line 219 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-enabled/secure.conf: /etc/apache2/sites-enabled/secure.conf:1: <VirtualHost> was not closed.
Action 'configtest' failed.
The Apache error log may have more information.
how to fix this? i made secure.mydoaminname.com but when reload apache2 i got this error!
 

Multivit4min

Member
Sep 2, 2015
27
49
53
I dont know if i should laugh or cry....
It already tells you in which file the Error is and what Error you have....

I dont think you are seriously trying to understand what you do
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
Syntax error on line 1 of /etc/apache2/sites-enabled/secure.conf: /etc/apache2/sites-enabled/secure.conf:1: <VirtualHost> was not closed.
As it says <VirtualHost> was not closed. Simply add </VirtualHost> and it should be fine.
 

Derp

Retired Staff
Contributor
Apr 30, 2015
933
1,017
217
Just.. please stop! You're dealing with apache configs (apache won't tolerate even the slightest error) and from what I've seen, you are not able to propperly administer a webserver!
Easy Solution (I'm sure you're looking for easy :3): Switch to a managed webhosting provider!
 

Alligatoras

Administrator
Mar 31, 2016
2,570
12
2,857
381
Hey, in this post im gonna explain, how to forward 2 domains (in this case forum.mydomain.us and download.mydomain.us) into different folders (in this case /var/www/forum/ and /var/www/download). This will only work if you use an Apache server as your webserver.

First you should connect to your server through putty. Now you should install an editor. I'm gonna use nano. To install it, type:

Now we create a new virtual host. I'll name it forum because my domain is forum.mydomain.us.

Now type the following in your .conf

Now, we create a second host and name it download.conf. We add the same stuff as in the forum.conf, but we have to change some things like the DocumentRoot etc.


If you done this, you have to enable the .conf's and restart your apache server



If you made everything right, it should work now :) If there are still any questions, feel free to ask me.

Sorry for my english, im german :)
Nice job my friend, i am pretty sure this will help me :) i was wondering though how this could happen!
 

Alligatoras

Administrator
Mar 31, 2016
2,570
12
2,857
381
Hey, in this post im gonna explain, how to forward 2 domains (in this case forum.mydomain.us and download.mydomain.us) into different folders (in this case /var/www/forum/ and /var/www/download). This will only work if you use an Apache server as your webserver.

First you should connect to your server through putty. Now you should install an editor. I'm gonna use nano. To install it, type:

Now we create a new virtual host. I'll name it forum because my domain is forum.mydomain.us.

Now type the following in your .conf

Now, we create a second host and name it download.conf. We add the same stuff as in the forum.conf, but we have to change some things like the DocumentRoot etc.


If you done this, you have to enable the .conf's and restart your apache server



If you made everything right, it should work now :) If there are still any questions, feel free to ask me.

Sorry for my english, im german :)
I got a quick question!
I did all steps on my vps and worked correctly!
BUT: now that i changed vps (company i mean) and i did the steps again it doens't work. Just goes to the default: var/www/html

How can i solve this??? :)
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
Did you reload apache after you enabled the configs? If not do it :) If that is not the problem... I would say let's talk in teamspeak so we can find your issue :)
 

Alligatoras

Administrator
Mar 31, 2016
2,570
12
2,857
381
Did you reload apache after you enabled the configs? If not do it :) If that is not the problem... I would say let's talk in teamspeak so we can find your issue :)
Yes i did reload apache! I will be able in about 9 hours for teamspeak, if you can :)
 
Top