LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to configure multiple websites on one PC? (https://www.linuxquestions.org/questions/linux-networking-3/how-to-configure-multiple-websites-on-one-pc-217494/)

<Ol>Origy 08-14-2004 08:57 AM

How to configure multiple websites on one PC?
 
Hello!

This is my first time setting up a website on my own static-IP server. I myself do not have much knowledge on networking, domains, subdomains, virtual hosts, DNS, etc. so before I attempt to configure anything I wish to get some instructions and help. I have searched these forums for any information and I did find some interesting things which unfortunately were not enough to answer my question. Anyway...
My goal is to set up a number of websites that can be accessed by subdomains ("http://website1.mydomain.com", "http://website2.mydomain.com" for example) on one linux computer with a static IP. I have my own Red Hat 9 linux PC that I use as a gateway, firewall and webserver (apache 2).
I have not yet registered a domain but suppose I register a domain like "www.mydomain.com" and set it to forward to my static IP, port 80. Now as I only have one static IP I would like to setup a number of websites on it and allow them to be accessed by subdomains. The question is how do I achieve that. I do prefer to have everything (including subdomains if possible) configured on my own server.
How do I configure my linux server to recognise when a user types a subdomain in his browser like "myfriend.mydomain.com" to access my PC and how to forward him to the appropriate website? :confused:
Having set up each website to be in its own folder, I had something like this in mind:

http://www.mydomain.com => /var/www/html/root
http://myname.mydomain.com => /var/www/html/myname
http://myfriend.mydomain.com => /var/www/html/myfriend
...

In the past I have read the Apache and virtual hosts configuration manual but I did not fully understand it.
I could use subfolders ("http://www.mydomain.com/myname" and "http://www.mydomain.com/myfriend") instead but I truly wish to use subdomains.


Any help, helpful links and/or info would be appreciated.

david_ross 08-14-2004 09:11 AM

You could use something like:
Code:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /home/httpd/domain1
    ServerName www.domain1.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /home/httpd/domain2
    ServerName www.domain2.com
</VirtualHost>


<Ol>Origy 08-14-2004 10:17 AM

Quote:

Originally posted by david_ross
You could use something like:
Code:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /home/httpd/domain1
    ServerName www.domain1.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /home/httpd/domain2
    ServerName www.domain2.com
</VirtualHost>


Those are two different domains. I would like to use only one domain and a lot of subdomains (subdomains = "test1.samedomain.com" and "test2.samedomain.com" or am I wrong?). Will your code work for one domain with subdomains? Like this:
Code:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /home/httpd/domain1
    ServerName site1.domain.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /home/httpd/domain2
    ServerName site2.domain.com
</VirtualHost>


david_ross 08-14-2004 10:20 AM

www is just a subdomain of a domain too. So yes it will work.

If you have multiple names that you want to serve the same content for then you can use a ServerAlias directive as well to list the alternative names.

<Ol>Origy 08-14-2004 02:15 PM

Okay. One more question.
I do not have a registered domain yet but I do wish to test your code.
Will it do if I just replace the domain name with my IP for now so I can send the URL's to my friends who will try to access the sites?

http://www.mydomain.com => http://(my IP - xxx.xxx.xxx.xxx)
http://myname.mydomain.com => http://myname.(my IP - xxx.xxx.xxx.xxx)
http://myfriend.mydomain.com => http://myfriend.(my IP - xxx.xxx.xxx.xxx)

and configure httpd.conf like this:

Code:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /var/www/html/root
    ServerName (my IP - xxx.xxx.xxx.xxx)
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html/myname
    ServerName myname.(my IP - xxx.xxx.xxx.xxx)
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html/myfriend
    ServerName myfriend.(my IP - xxx.xxx.xxx.xxx)
</VirtualHost>

Is this even possible? I'm a little concerned about the IP itself as only my IP would reflect to "www.mydomain.com" so according to that "myname.(my IP - xxx.xxx.xxx.xxx)" should reflect to "myname.www.mydomain.com". Does that work?

P.S. Nice signature, david_ross ;)

david_ross 08-14-2004 03:33 PM

No - it won't work like that but you can use the hosts file of your client PC.

Just add an entry (line) like:
ip.of.server.here me.domain.com friend.domain.com www.domain.com domain.com

<Ol>Origy 08-15-2004 02:16 AM

You are correct. I edited hosts file on my internal WinXP computer and it worked properly. All subdomains could be accessed properly.
Now as I noticed you included all available subdomains in the hosts file. When I removed the subdomains from the hostsfile and left the main domain still in there I could no longer access subdomains. Will I have to include/specify all subdomains where I plan to register my domain (this is what I was trying to avoid all the time, heh)?

david_ross 08-15-2004 07:48 AM

You will only need to register the domain and from then on you will need to set up A records in your DNS server for each subdomain and point them to the IP address of your server.

<Ol>Origy 08-16-2004 07:16 AM

Okay. I attempted to avoid DNS because it's this DNS stuff that confuses me most because I don't fully understand it. Actually I don't understand it at all. :scratch: So shortly is what I am trying to achieve NOT possible without a proper configuration of records on a DNS server? :confused:

EDIT: I am talking about subdomains. I know it is impossible for full domains.


All times are GMT -5. The time now is 06:22 AM.