Jump to content

Communication between Virtual Hosts on the Same Machine


iwato

Recommended Posts

Problem: I would like to practice the cURL library, but have only one computer available to me at the moment.Question: Is it possible to communicate between two virtual hosts on the same operating system? If so, how would one go about coordinating two different web applications using the same webserver? I am working in a MAMP environment.Roddy

Link to comment
Share on other sites

Yes. It's possible. In fact, that's the idea of virtual hosts after all - give different content based on the domain (technically, the HTTP "Host" header) the user requested.There's no special "coordination" really. You just set up the two virtual hosts, and operate on them as if they're two separate web servers.The way you basically do it is like:

<VirtualHost example.com:80>DocumentRoot "D:/Path/To/The/Document/Root/Of/example.com"#Other directives</VirtualHost>

copy&pasted multiple times for each virtual host you want and altered accordingly for each.In case the request comes with another host header, Apache will fallback to the default ("real") host.Oh, and you must add

NameVirtualHost *

To turn on virtual hosting matches for everything (you can limit it by port, IP and/or name).

Link to comment
Share on other sites

Depending on which type of VM software you are using, (I am using VirtualBox running an XP guest OS, on an OSX host), I can access my host's localhost:// by typing 10.0.2.2 in the guest OS's browser window. Not sure if that helps you at all.

Link to comment
Share on other sites

Depending on which type of VM software you are using, (I am using VirtualBox running an XP guest OS, on an OSX host), I can access my host's localhost:// by typing 10.0.2.2 in the guest OS's browser window. Not sure if that helps you at all.
I am running with MAMP-Pro and have discovered that it is very easy to set up a virtual host once you know approximately what needs to be done. Now, all I have to figure out is how to communicate between my real and virtual servers. They even share the same file folder. I am very pleased that it was so easy to set up.Roddy
Link to comment
Share on other sites

Yes. It's possible. In fact, that's the idea of virtual hosts after all - give different content based on the domain (technically, the HTTP "Host" header) the user requested.
This was very encouraging. So much so, that I have already set up my first virtual host.
There's no special "coordination" really. You just set up the two virtual hosts, and operate on them as if they're two separate web servers.
This I have yet to discover, but will hopefully soon realize to be true.
The way you basically do it is like:
<VirtualHost example.com:80>DocumentRoot "D:/Path/To/The/Document/Root/Of/example.com"#Other directives</VirtualHost>

copy&pasted multiple times for each virtual host you want and altered accordingly for each. You must add

NameVirtualHost *

To turn on virtual hosting matches for everything (you can limit it by port, IP and/or name).

Unfortunately, this was not so clear. Are <VirtualHost> and </VirtualHost> HTML tags? Where are they placed?Roddy
Link to comment
Share on other sites

I don't know why I assumed you know how to configure Apache...All settings of Apache originate in a file called "httpd.conf", typically located in a folder under the main Apache folder... search for "httpd.conf" and you should be able to find it. Apache has only one such file, and other programs (including other HTTP servers) don't typically use this name. Open it with a text editor, and add/edit/remove any settings with that. For the settings to take effect, you need to not only save the file, but restart Apache.

Link to comment
Share on other sites

All settings of Apache originate in a file called "httpd.conf", typically located in a folder under the main Apache folder... search for "httpd.conf" and you should be able to find it. Apache has only one such file, and other programs (including other HTTP servers) don't typically use this name.
I found this folder, but when I opened it see how MAMP Pro had configured my virtual host, I found nothing. Moreover, when I checked the status of my virtual host using the apachectl -V command in my machine's terminal program; it simply replied OK, but provided no further information -- like a directory path to the appropriate httpd.conf file.For the moment, I am somewhat perplexed by what has happened.By the way, the people at MAMP Pro never replied to my inquiry about how to set up x-debug. So, I am reluctant to post another inquiry in their forum, and the documentation for their software is very scanty.Roddy
Link to comment
Share on other sites

Perhaps because there are no virtual hosts by default. By default, you have one "real" host. You need to actually add the lines to the httpd.conf file, and restart Apache to get vritual hosts.

By the way, the people at MAMP Pro never replied to my inquiry about how to set up x-debug. So, I am reluctant to post another inquiry in their forum, and the documentation for their software is very scanty.
Frankly, I was going to be more surprised if they were helpful.
Link to comment
Share on other sites

Perhaps because there are no virtual hosts by default. By default, you have one "real" host. You need to actually add the lines to the httpd.conf file, and restart Apache to get vritual hosts.
This does not appear to be the case. I created the virtual host within the MAMP-Pro framework and tested for its presence, before I went to my machine's terminal program to discover the file that defined its presence.Roddy
Link to comment
Share on other sites

Wha...?I have no idea what MAMP does exactly, but the way described above is how you do it "manually".

Link to comment
Share on other sites

I have no idea what MAMP does exactly, but the way described above is how you do it "manually".
In time I will likely discover it. For the moment I am happy that I have made an important step toward experimentation with HTTP protocol.Many thanks!Roddy
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...