Virtual Host and 'Main' server conflict

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Virtual Host and 'Main' server conflict

Postby smsmith0223 » 09. August 2006 01:06

Sorry if I'm posting something that's been answered before, I searched for it and found nothing that helped me out for what I'm doing. Ok so here's my problem I have a server running as a testing server for when I'm working on websites and what not. Right now I have a dynamic IP address so I'm using DynDNS's services. I have a a Virtual Host set up and it works when I type in the domain both from a WAN and LAN connection. I have my 'main' server set up (password protected and secure) so that I can view access logs and other useful debugging information that should be private. All of this works so far, now with DynDNS I have wildcards enabled (example: my-domain.com; www.my-domain.com; mail.my-domain.com) when using the wildcards I should be able to have sub domains (at least from what I understand, and that's the easiest way to explain it) I currently am not using the wildcards so I just now came across this problem when I tried using one. I created a second Virtual Host (design.my-domain.com) so it would still use the same domain as my first VH but it uses a wildcard and should point it to the directory specified in my second VH (if there's another way to set up Virtual Hosts and using wildcards let me know) anyways I found out when other wildcards are put in before the domain it points the user to my 'main' server. I also had to put my 'main' server into a Virtual Host to make it work correctly with my first Virtual Host if there's a better or proper way to do that please let me know. So to cut it short I need to know how to set up two virtual hosts with the same domain name but one with a wildcard (example: 1st VH - my-domain.com; 2nd VH - design.my-domain.com) and have the two working properly without it conflicting my 'main' server which should only be able to be accessed by entering the IP address and should never be able to be accessed when using my domain name... sorry it's so long just wanted to get as much detail in there as possible. Thanks in advance
smsmith0223
 
Posts: 4
Joined: 09. August 2006 00:38

Postby Izzy » 09. August 2006 01:39

No need for muliple vhost in your case I believe. Just use:
ServerAlias mysubdomain.my-domain.com

Example using the localhost as the main domain and the subdomain is configured at DynDns and is notified automagically when my dynamic IP changes:
Code: Select all
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/Program Files/Apachefriends/xampp/htdocs"
ServerAlias izzyz.homeip.net
ServerAdmin you@my-domain.com
<Directory "C:/Program Files/Apachefriends/xampp/htdocs" >
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

The above is an example only and should not be used in practice as it may be a security risk if you have not set up XAMPP securely. You can substitute localhost for my-domain.com and you can add as many ServerAlias lines as is required including:
www.my-domain.com
mail.my-domain.com
ftp.my-domain.com
anysubdomain.my-domain.com
etc
etc
etc.

Use a different virtual host container for a different main domain name.

No need to use a different virtual host container for subdomains just use a ServerAlias entry and point the subdomains to their own DocumentRoot and <Directory></Directory> directories.

Use this at a command prompt within the xampp/apache/bin directory to check sysntax before re-starting your server after editing Apache .conf files:
apache -S

It will return Syntax OK if all is well
It will return the errant line(s) if you have a syntax error which would normally prevent Apache from restarting.

Hope this is what you wanted and all points have been covered for you.
:)
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby Wiedmann » 09. August 2006 01:39

Sorry, can you break down this text into 4-6 short sentences with paragraphs, where you describe your basic problem? Possibly with a configuration example which you have already.

(It's really hard to read the above text...)
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby smsmith0223 » 09. August 2006 03:13

What Izzy said was exactly what I wanted, and my reason for not posting my configuration files was that I would have to go through and edit every part that I did not want shared and that would have taken alot longer.

Izzy wrote:No need to use a different virtual host container for subdomains just use a ServerAlias entry and point the subdomains to their own DocumentRoot and <Directory></Directory> directories.


My only question now is how do I set up different ServerAliases to point to differnt directories and roots? I looked at the docs on httpd.apache.org and couldn't really figure out a way to do this.
smsmith0223
 
Posts: 4
Joined: 09. August 2006 00:38

Postby Izzy » 09. August 2006 03:32

As Weidmann pointed out, splitting your post into many paragraphs makes it much easier to read especially for those whose native language is not English. ;)

This page might give you some ideas:
http://httpd.apache.org/docs/1.3/vhosts/examples.html

If you want a different location for your subdomain files then use another virtual host container.
Code: Select all
<VirtualHost *:80>
ServerName my-domain.com
ServerAlias www.my-domain.com
DocumentRoot "C:/Program Files/Apachefriends/xampp/htdocs/mydomain"
ServerAdmin you@my-domain.com
<Directory "C:/Program Files/Apachefriends/xampp/htdocs/mydomain" >
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


<VirtualHost *:80>
ServerName subdomain.my-domain.com
ServerAlias www.subdomain.my-domain izzyz.homeip.net www.izzyz.homeip.net
DocumentRoot "C:/Program Files/Apachefriends/xampp/htdocs/mydomain/mysubdomain"
ServerAdmin you@subdomain.my-domain.com
<Directory "C:/Program Files/Apachefriends/xampp/htdocs/mydomain/mysubdomain" >
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Your DNS should know of your subdomain.my-domain.com so your subdomain can be found from off the Internet by typing the url in a would be visitor's web browser.

Here is another link with some useful info:
http://www.linuxdevcenter.com/pub/a/lin ... index.html
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby smsmith0223 » 09. August 2006 08:59

After setting up my Virtual Hosts and using the ServerAlias directive I fixed my problem. Thanks Izzy

By adding a wildcard alias (*) to my virtual host no one can gain access to my 'main' server by typing in some random subdomain on my domain. I realized the reason for this behavior was because all wildcards get pointed to my domain name.
Code: Select all
    ServerName my-domain.com
    ServerAlias my-domain.com *.my-domain.com


For my subdomains that point to a different location I set up a virtual host using a wildcard before the domain in the ServerAlias directive
Code: Select all
    ServerName my-domain.com
    ServerAlias subdomain1.my-domain.com


Now that my other problems have been solved I'll reword my other problem I'm having so it's easier to understand.

When I am not using a virtual host for my 'main' server, the IP of my server points to the last virtual host loaded.
For now I had to disable most of the stuff for the 'main' server in the conf file and set up a seperate virtual host for it.
This seems very redundent since the 'main' server should not need to be a virtual host.

* The way I want this to work is so that all requests for a domain are pointed to the directories associated with that domain, and all requests for my IP address are pointed to my 'main' server.

Any ideas on this are appreciated, but if not what I’m doing now seems to work.
smsmith0223
 
Posts: 4
Joined: 09. August 2006 00:38

Postby Izzy » 09. August 2006 09:20

Your first entry in the httpd-vhost.conf file should be:
Code: Select all
<VirtualHost *:80>
DocumentRoot "C:/Program Files/xampp/htdocs"
ServerName localhost:80
</VirtualHost>


Then your other vhosts come after that.

You are on a dynamic IP?
or do you have a static IP you want to use for your main domain?

A dynamic IP is not possible unless you want to change it manually every time the IP changes. You have already used DynDNS to send a request for your changed IP to go where ever you configured it to go.
This handles the dynamic IP:
<VirtualHost *:80>

A static IP is handled like this:
<VirtualHost 123.123.123.123:80>
ServerName 123.123.123.123:80

Just to add I dropped DynDNS and went with zoneedit.com which has more control over a domain's zone file. The first 5 domains are free. Each domain can have multiple subdomains of your choice or you can use their subdomains.
You can also set up your MX records so you can effectively run a domain mail server from XAMPP.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby smsmith0223 » 09. August 2006 10:16

Thank you again, Izzy, once again you have solved my problem. Also thanks for the tip about DynDNS and zoneedit.

Currently I have a dynamic IP, I will be getting a static one soon.

I read on another forum that for the server name each one should be unique. From what you said they should just all be the same and use localhost:80 on all of them for both my virtual hosts and my main server, I'm assuming then I would use server aliases to access each one.

Now that everything works with my dynamic IP, will it still work once i switch to a static IP?
smsmith0223
 
Posts: 4
Joined: 09. August 2006 00:38

Postby Izzy » 09. August 2006 10:28

Because we are using the wildcard it will work with any IP. You can drop the wildcard and insert your static IP on an per domain basis as required.
Thats the bit here:
<VirtualHost *:80>
<VirtualHost localhost:80>
<VirtualHost 127.0.0.1:80>
<VirtualHost 123.123.123.123:80>
Etc.

The ServerName is your domain name or static IP.

The ServerAlias is any another name that can be used as well as ServerName
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 39 guests