Forum Moderators: phranque

Message Too Old, No Replies

Setting up virtual host to specific url

Setting up virtual host to specific url

         

drooh

10:12 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



How would i do this?

<VirtualHost *:80>
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/"
ServerName http://somesite.example.com/
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/anothersite/"
ServerName http://somesite.example.com/anothersite/
</VirtualHost>

I want to be able to assign a root directory to a url like
http://somesite.example.com/anothersite/

[edited by: jdMorgan at 6:53 pm (utc) on Dec. 3, 2008]
[edit reason] Please use example.com only. [/edit]

drooh

1:47 am on Dec 3, 2008 (gmt 0)

10+ Year Member



Do I need to get a domain name and use zone edit and set up sub domains instead?

jdMorgan

6:55 pm on Dec 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not at all sure I understand your question.

A DocumentRoot is assigned to a hostname (generally speaking, to a servername, virtualhost, or domain). So it's not clear how you want to "associate" your subdirectory (/anothersite) with a DocumentRoot; Technically, /anothersite is a child subdirectory of the document root directory in the domain from which /anothersite is requested.

It might be helpful to back up one step, and describe what your goal is -- What are you trying to accomplish?

Jim

drooh

7:35 pm on Dec 3, 2008 (gmt 0)

10+ Year Member



I am using a free service to get a domain name, and they limit up to 5 free names. Every new client I get I am building the site on my home server 1st before uploading it to the main server. So instead of creating multiple new names for each client and setting up a vhost for each I was trying to see if there was a way to do it with one domain name.

So for instance id like when you go to

http://example.com/anothersite/

that is would act as if
C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/anothersite/
was the root and not
C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/

Make sense?
The reason for this is because of the inner css and php linking, it breaks down otherwise if you dont have the root set.
Example would be a link
<a href="/about/">about</a>

would link to
http://example.com/about/

not
http://example.com/anothersite/about/

which is what im trying to do.

I realize what Im trying to do may not be possible or may not even be logical. Im just trying to set up a new vhost for each client i get and looking for the most cost effective way to do so.

I know I could use another free service to set up free unlimited sub domains and that seems to work, but that means ill need to at least purchase one name 1st.

Aerosoft Web

11:18 pm on Dec 3, 2008 (gmt 0)

10+ Year Member



You could use host aliases to do what you want, though I can't say that the context in which you're wanting to use them here is what they're intended to solve. Assuming the following file structure:

/home/projects
/home/projects/client1
/home/projects/client2
/home/someOtherFolder/anotherFolder/client3

... the following vhost can be been created:

<VirtualHost *:80>
DocumentRoot /home/projects/
ServerName myserver.localhost
Alias /client1 /home/projects/client1
Alias /client2 /home/projects/client2
Alias /client3 /home/someOtherFolder/anotherFolder/client3
</VirtualHost>

From that, you can probably see that the following urls will point to the following locations:

myserver.localhost -> /home/projects
myserver.localhost/client1 -> /home/projects/client1
myserver.localhost/client2 -> /home/projects/client2
myserver.localhost/client2 -> /home/someOtherFolder/anotherFolder/client3

More on host aliases here ...

[fancybread.com...]

Hope this helps. Good luck!

drooh

5:05 am on Dec 4, 2008 (gmt 0)

10+ Year Member



I seem to be having trouble with this. I am on a windows server too.

<VirtualHost *:80>
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
ServerName [mydomain.org...]
Alias /anotherdomain.com "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/anotherdomain.com"
</VirtualHost>

Can you see what I need to do here to make this work?

Aerosoft Web

5:40 am on Dec 4, 2008 (gmt 0)

10+ Year Member



It looks ok to me. Try these steps:

1) Remove the Alias for now, so that you only have a DocumentRoot and ServerName
2) Verify mydomain.org is in your hosts file
3) Restart Apache

Can you hit [mydomain.org?...] If not, then you need to debug your virtual host first.

drooh

6:40 am on Dec 4, 2008 (gmt 0)

10+ Year Member



Im not sure I have a hosts file, i have the domain set in my httpd.conf file.

I can hit [mydomain.org...] so i know thats working..

Aerosoft Web

7:13 am on Dec 4, 2008 (gmt 0)

10+ Year Member



OK. Are you sure you restarted apache when you added the alias?

drooh

7:27 am on Dec 4, 2008 (gmt 0)

10+ Year Member



yes, ive been restarting it like a mad man

im not sure if this is even possible the way i want to use this...

thinking now that i should just get a paid domain name and use zoneedit to create sub domains for each client test environment.

jdMorgan

12:37 pm on Dec 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All internet-capable operating systems include a hosts file, and it is always named 'hosts' -- no file extension, and all-lowercase. Its location varies, but it is always a plain-text file and in the same format, regardless of the OS. You can search your machine to find it. It's in \windows\system32\drivers\etc\ on WinXP, for example.

Jim

drooh

7:13 am on Dec 5, 2008 (gmt 0)

10+ Year Member



I was able to find the hosts file and add my domain name to it, also I was able to somewhat get the alias to work but the problem I was having was

<a href="/about/">about</a>

was linking to

something.mydomain.org/about

and not

something.mydomain.org/client1/about

I wanted it to treat
something.mydomain.org/client1/
as the root even for linking in the html and css

this way when i upload and go live to the main server I dont have to change the html and css linking from
<a href="/client1/about/">about</a>
to
<a href="/about/">about</a>

Is there any way to make this happen by changing the vhosts or anything in apache? Is this just not the way it works?

Am I better off using sub domains on my home server for setting up new client test environments such as

client1.mydomain.org
client2.mydomain.org
client3.mydomain.org

jdMorgan

2:58 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'd be better off with subdomains than with subdirectories, since each site would then have a "solid" DocumentRoot.

And even better would be to define a VirtualHost per client, and fully-emulate the domain.

Basically, you want your development and test servers set up exactly the way the client's server is set up. This takes some work at the front end of a project, but can save enormous amounts of time later. It also prevents potentially-very-nasty surprises when moving from test to production (a time when the client is likely impatient and watching you very closely).

Jim

Aerosoft Web

3:54 pm on Dec 5, 2008 (gmt 0)

10+ Year Member



Yes, a new vhost is the best way to go here....I agree with Jim.

I've never had trouble setting up alias' before ... but even without those troubles, I use separate vhosts for each client in my dev and test environments for the exact reasons Jim states...else you will hit problems (eventually).

drooh

7:05 pm on Dec 5, 2008 (gmt 0)

10+ Year Member



ok, so with that here is my plan.

purchase a domain name for 10 bucks that is something general that represents my home server (like "homeserver.com")
use zoneedit to set up unlimited sub domains for each client (like "clientz.homeserver.com")
assign a new vhost for each client

is there another way to do this without purchasing a domain name and using zone edit? is there some way to do this in apache

its important for clients to be able to see the test environment from the outside, so i cant just use localhost

jdMorgan

9:22 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are setting up a server for local development, test, and debug, you do not need to purchase any domain names at all. It does not matter that your ISP limits you to five, nor would it matter if your ISP limited you to zero.

Define any and all the domains you like in the hosts file as pointing to 127.0.0.1 on your server machine. On all other machines in your network, use their host files to define those same domains as pointing to the LAN IP address of your server, e.g. 192.168.0.10)

The hosts file acts as a simple DNS server on each of these machines; Any entry found in the hosts file will override and prevent the DNS requests of any and all internet-capable programs on your machine. Therefore, you are effectively running a 'private DNS server' on each of these amchines, and you can define any domain you like, whether it is registered or not.

For example, if you put "127.0.0.1 www.google.com" in your hosts file, then you can set up ServerName www.google.com in a vHost container, and pretend you are Sergey Brin... :)

Only in the case where you want people from outside your network to be able to access these servers by domain name do you need to worry about registering the domain names. And in that case, you could very well set up reverse proxies from a public domain of client-subdomain.youronedomain.com to clientname.com inside your network.

When you finish testing and take a site live on a public server, simply delete the relevant entries from your hosts files, so that your machines will then use the public DNS system to resolve these domains' IP addresses.

HTH,
Jim

[edited by: jdMorgan at 9:24 pm (utc) on Dec. 5, 2008]

drooh

3:10 am on Dec 6, 2008 (gmt 0)

10+ Year Member



ok i purchased a domain name and set it up with zoneedit and i can hit
myserver.com but ive also set up some vhosts and subdomains. its very weird whats happening.

In firefox and Ie7 I get
Error 400 - Bad Request
when i try to hit client1.myserver.com

but using ie6 its fine,

also while i was out at the coffee shop i could hit
client1.myserver.com
just fine.

furthermore my cell phone browser can hit
client1.myserver.com
just fine

is this temporary and i just need to wait? is there some kind of internal network issue going on here?

drooh

5:13 am on Dec 6, 2008 (gmt 0)

10+ Year Member



the ip address of client1.myserver.com is still with yahoo however just
myserver.com is my home ip address...weird? im guessing this is because the dns change is still propagating..?

drooh

9:44 pm on Dec 7, 2008 (gmt 0)

10+ Year Member



everything works now, guess it was just propagating