LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2004, 08:57 AM   #1
<Ol>Origy
Member
 
Registered: Aug 2003
Location: Slovenia
Distribution: Arch, Debian, Embedded
Posts: 136

Rep: Reputation: 15
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?
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.
 
Old 08-14-2004, 09:11 AM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
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>
 
Old 08-14-2004, 10:17 AM   #3
<Ol>Origy
Member
 
Registered: Aug 2003
Location: Slovenia
Distribution: Arch, Debian, Embedded
Posts: 136

Original Poster
Rep: Reputation: 15
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>
 
Old 08-14-2004, 10:20 AM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
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.
 
Old 08-14-2004, 02:15 PM   #5
<Ol>Origy
Member
 
Registered: Aug 2003
Location: Slovenia
Distribution: Arch, Debian, Embedded
Posts: 136

Original Poster
Rep: Reputation: 15
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

Last edited by <Ol>Origy; 08-14-2004 at 02:16 PM.
 
Old 08-14-2004, 03:33 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
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
 
Old 08-15-2004, 02:16 AM   #7
<Ol>Origy
Member
 
Registered: Aug 2003
Location: Slovenia
Distribution: Arch, Debian, Embedded
Posts: 136

Original Poster
Rep: Reputation: 15
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)?
 
Old 08-15-2004, 07:48 AM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
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.
 
Old 08-16-2004, 07:16 AM   #9
<Ol>Origy
Member
 
Registered: Aug 2003
Location: Slovenia
Distribution: Arch, Debian, Embedded
Posts: 136

Original Poster
Rep: Reputation: 15
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. So shortly is what I am trying to achieve NOT possible without a proper configuration of records on a DNS server?

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

Last edited by <Ol>Origy; 08-16-2004 at 07:19 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache - running multiple websites on one host xtra Linux - General 5 06-30-2010 04:51 AM
serving multiple domain websites on one server? gsgleason Linux - Software 1 06-03-2005 10:50 AM
multiple file upload for websites? sohmc Linux - Networking 4 02-23-2005 07:43 AM
Running multiple SSL websites on one server tictocdoc Linux - Networking 1 07-07-2004 03:26 PM
How-to setup on Apache some Multiple Namebased Virtual Websites with cgi-bin FunkFlex Linux - Newbie 0 02-08-2002 08:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration