vhosts & different ports

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

vhosts & different ports

Postby janimal » 11. March 2010 17:09

Hi all,
I have been using xampp for quite a while to develop sites on my local machine. Usually I set-up virtualhosts and then edit my hosts file so I can access them by name in my browser.

However - I get tired of having to upload in-development sites to a webserver so that the client can preview how the design is going etc..

My IP address is dynamic, but in reality it hasn't changed in over 18 months even when I have released it, left the router off and gone on holiday for two weeks I always end up with the same ip again!

So what I wanted to do was to make my local virtual hosts accessible from the network so that i could send a client a url http://myipaddress/ and they can see the site. I can do this no problem. So I now want to allow several clients to get previews of sites. eg
client1's site http://myipaddress
client2's site http://myipaddress:40321

This is what I have done...

forwarded the ports 80 and 40321 from the router to the appropriate machine

The Setup
In http-conf...
Code: Select all
Listen 80
Listen 40321


in httpd-vhosts...
Code: Select all
NameVirtualHost *:80
NameVirtualHost *:40321

  <VirtualHost *:40321>
    DocumentRoot "G:\web_development\websites\work\annaspan\html"
    ServerName annag
    <Directory "G:\web_development\websites\work\annaspan\html">
      Order allow,deny
      Allow from all
      AllowOverride All
    </Directory>
  </VirtualHost>

  <VirtualHost *:80>
    DocumentRoot "G:\web_development\websites\work\rebelit\wp"
    ServerName rebelwp
    <Directory "G:\web_development\websites\work\rebelit\wp">
      Order allow,deny
      Allow from all
      AllowOverride All
    </Directory>
  </VirtualHost>


The Problem Result
Now when I someone trys http://myipaddress/ they get served the rebelwp site
however when someone trys http://myipaddress:40321 they still get served the rebelwp site and not the annag site
in the browser the url reverts back to http://myipaddress/

Alternatives
I have also tried the Listen, NameVirtualHost and VirtualHost directives using the machine's IP address and the loopback address
in various combinations.

So I have searched all afternoon on the internet & read and re-read the apache org docs on vhosts & I just can't see what I am doing wrong?

I have verified that the router is forwarding correctly and the server has a fixed IP on the local network otherwise the access to the single site wouldn't work.

Can anyone point out my stupidity please?

Thanks a lot,
Janimal
:?:
janimal
 
Posts: 7
Joined: 11. March 2010 16:42

Re: vhosts & different ports

Postby CraigS » 11. March 2010 17:46

What virtual hosts do is listen for the domain name from the browser and then serve the corresponding site. If it isnst known, the default site is sent.
Your 'ServerName annag' in the config might be your problem; This is telling the apache server to listen for 'Annag' in the browser window.

What you can do is have a sub domain forward to the site for you. (if you have access to create a subdomain)
What you will do is create an anna.yourdomain.com and a rebelwp.yourdomain.com (whichever domain you use for testing, and have the subdomains point to the same ip. )


Sample Config in this respect for you:
Code: Select all
<VirtualHost *:40321>
    DocumentRoot G:\web_development\websites\work\annaspan\html
    ServerName annag.yourdomain.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot G:\web_development\websites\work\rebelit\wp
    ServerName rebelwp.yourdomain.com
</VirtualHost>
User avatar
CraigS
 
Posts: 16
Joined: 10. March 2010 23:37
Location: Wisconsin, USA

Re: vhosts & different ports

Postby janimal » 11. March 2010 17:55

Hi Thanks for your reply,
But the browser - especially a client's external to my network would look for that via DNS - these are not pointed at by nameservers only local. Unless I have misunderstood your response? I can be pretty stupid sometimes :oops:
janimal
 
Posts: 7
Joined: 11. March 2010 16:42

Re: vhosts & different ports

Postby Nobbie » 11. March 2010 18:01

Your configuration is real nonsense, its a crappy mix of NameBased and IP-based VirtualHosts, but none of them working.

Try this configuration instead:

Code: Select all
#NameVirtualHost *:80
#NameVirtualHost *:40321 // or remove these lines,  are completely nonsense

<VirtualHost 192.168.178.20:40321>
    DocumentRoot "G:\web_development\websites\work\annaspan\html"
    ServerName annag
    <Directory "G:\web_development\websites\work\annaspan\html">
      Order allow,deny
      Allow from all
      AllowOverride All
    </Directory>
</VirtualHost>

<VirtualHost 192.168.178.20:80>
    DocumentRoot "G:\web_development\websites\work\rebelit\wp"
    ServerName rebelwp
    <Directory "G:\web_development\websites\work\rebelit\wp">
      Order allow,deny
      Allow from all
      AllowOverride All
    </Directory>
</VirtualHost>


You must replace "192.168.178.20" by the LAN-IP of your server, which should be similar. Then restart Apache. And urgently read some more docs.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: vhosts & different ports

Postby janimal » 11. March 2010 18:20

Hi Thanks for your response

this is my config now...

removed the NameVirtualHost directives and configured virtual hosts thus...

Code: Select all
  <VirtualHost 192.168.2.3:40321>
    DocumentRoot "G:\web_development\websites\work\annaspan\html"
    ServerName annag
    <Directory "G:\web_development\websites\work\annaspan\html">
      Order allow,deny
      Allow from all
      AllowOverride All
    </Directory>
  </VirtualHost>

  <VirtualHost 192.168.2.3:80>
    DocumentRoot "G:\web_development\websites\work\rebelit\wp"
    ServerName rebelwp
    <Directory "G:\web_development\websites\work\rebelit\wp">
      Order allow,deny
      Allow from all
      AllowOverride All
    </Directory>
  </VirtualHost>


http-conf set to listen on 80 & 40321

in browser type http::192.168.2.3:40321

and it displays rebelwp not annag as I said in my first post the browser url changes from http::192.168.2.3:40321 to http::192.168.2.3 once I hit return, could this indicate another issue?
janimal
 
Posts: 7
Joined: 11. March 2010 16:42

Re: vhosts & different ports

Postby Nobbie » 11. March 2010 18:40

Clear your browser cache.

Anyway - this is an *ugly* solution. You should not create "port based" VirtualHosts. Instead you should create domain names. If you dont want to create public domain names, ask your customers to edit their local hosts files and add the two server names:

Code: Select all
123.123.123.123  annag
123.123.123.123  rebelwp


The IP 123.123.123.123 must be replaced by your Public WAN-IP.

You should edit your server hosts file as well, but instead of using the Public WAN-IP, you must supply your local LAN-IP:

Code: Select all
192.168.2.3  annag
192.168.2.3  rebelwp


After then, edit your vhost-config and supply the following content:

Code: Select all
NameVirtualHost 192.168.2.3:80
<VirtualHost 192.168.2.3:80>
    DocumentRoot "G:\web_development\websites\work\annaspan\html"
    ServerName annag
    <Directory "G:\web_development\websites\work\annaspan\html">
      Order allow,deny
      Allow from all
      AllowOverride All
    </Directory>
</VirtualHost>

<VirtualHost 192.168.2.3:80>
    DocumentRoot "G:\web_development\websites\work\rebelit\wp"
    ServerName rebelwp
    <Directory "G:\web_development\websites\work\rebelit\wp">
      Order allow,deny
      Allow from all
      AllowOverride All
    </Directory>
</VirtualHost>


You may also remove the redirections of Port 40321 from your Router, you dont need it further more. If you did everything right and restarted Apache, you (and your clients) may reach your projects via

http://annag
http://rebelwp
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: vhosts & different ports

Postby janimal » 11. March 2010 18:55

Ok I will try that tomorrow to see if it works.

But I have to say asking my client to modify their hosts file is a lot uglier ,than simply giving them a URL don't you think? I would rather not do it, especially since some of my clients can barely use a browser let alone edit system files.

Personally I don't mind my xampp config being a bit ugly as long as it works. And I certainly don't mind opening up a port on the router occasionaly to let a client check out the current state of development.

The reason my config was as you say an ugly mix of vhost style is because locally I have never needed to worry about IPs - just edit my hosts file and give the vhost a name.

If there really is no way to specify a separate port for a vhost (although the documentation says there is, none of the provided examples seem to work with my xampp installation) then I think I'll just go back to uploading the sites to the web hosting for them to preview tedious, time consuming and error prone though it is.

Thanks for your input though.
janimal
 
Posts: 7
Joined: 11. March 2010 16:42

Re: vhosts & different ports

Postby Nobbie » 11. March 2010 19:13

janimal wrote:Ok I will try that tomorrow to see if it works.

But I have to say asking my client to modify their hosts file is a lot uglier ,than simply giving them a URL don't you think? I would rather not do it, especially since some of my clients can barely use a browser let alone edit system files.


Yes, definately.

But: you could (and *should*) do that job instead, you can have domain names for your (dynamic) IP. For example at www.dyndns.com. Of course, the domains are different to "annag" or "rebelwp", but you could (for example) get a domain name like janimal.dyndns.org and you may configure it to pass all subdomains (*-janimal.dyndns.org) to your Router (to the Public WAN IP).

After then you can create virtual hosts for servername annag.janimal.dyndns.org and rebelwp.janimal.dyndns.org (and any other name you like) and your customer simply have to enter http://annag.janimal.dyndns.org or http://rebelwp.janimal.dyndns.org or whatever you like. And: if eventually your (dynamic) IP changes, your customer dont need to change anything. You only have to configure your dyndns account to point to the appropriate IP. And the very best: many routers have built-in support for dyndns.com and similar services - so you only have to configure your Router once, and after everything will work automatically. It works like a real static domain with static IP.

You only have to change the server names in your VirtualHost Configuration and you should also adapt your hosts file (but only once. because you have to assign the local LAN IP to the dyndns domain names).

janimal wrote:Personally I don't mind my xampp config being a bit ugly as long as it works. And I certainly don't mind opening up a port on the router occasionaly to let a client check out the current state of development.


It is ugly. And not recommended. Think about the dyndns solution - thats the perfect way. And its not difficult and it works really great.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: vhosts & different ports

Postby janimal » 11. March 2010 19:19

You're right dyndns sounds like a much better solution - I'll look into it.

Thanks, :D
Janimal
janimal
 
Posts: 7
Joined: 11. March 2010 16:42

Re: vhosts & different ports

Postby CraigS » 11. March 2010 19:26

Agreed, i just wasnt sure why you wanted two ports ^_^ Makese sense that you were confused now!
User avatar
CraigS
 
Posts: 16
Joined: 10. March 2010 23:37
Location: Wisconsin, USA

Re: vhosts & different ports

Postby janimal » 11. March 2010 19:32

Got myself an account - and my router supports it.

Thanks Nobbie
janimal
 
Posts: 7
Joined: 11. March 2010 16:42

Re: vhosts & different ports

Postby janimal » 11. March 2010 20:11

just to let you know, that's working fine now with dyndns

thanks for your time & suggestions both
Janimal
janimal
 
Posts: 7
Joined: 11. March 2010 16:42

Re: vhosts & different ports

Postby Nobbie » 11. March 2010 20:13

janimal wrote:Got myself an account - and my router supports it.

Thanks Nobbie


You're welcome.

I just had a look to my dyndns account and found out, that the wildcard support (for subdomains) is not for free any more. Its part of the DynDNS Pro Package now. It has been free earlier.

Anyway, the DynDNS Pro Package is not expensive, it costs only 15$ a year. That's only a little more than one buck a month.

You really should go for the Pro Package with wildcard and subdomain support, it makes everything really easy for you and you can set up as many projects/subdomains as you want.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: vhosts & different ports

Postby Tyrael » 12. March 2010 11:03

NameVirtualHost isn't needed, if you dont want to use multiple virtualhost on the same ip+port.
This works for me:

Code: Select all
NameVirtualHost *:80

Listen 12345

<VirtualHost *:12345>
    ServerAdmin tyrael@localhost    DocumentRoot \work\xampp\htdocs\12345
    ServerName api.psp.loc
    ErrorLog \work\xampp\htdocs\12345\logs\error.log
    CustomLog \work\xampp\htdocs\12345\logs\access.log common
</VirtualHost>


My other vhosts are on the *:80, and they choosen based on their ServerName/ServerAlias property.

the ip/port based vhosting isn't ugly, more importantly, you can use different(every vhost can use its own) ssl certs with it, that you can't do with name based virtual hosts.

Tyrael
Tyrael
 
Posts: 5
Joined: 23. June 2007 15:51


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 106 guests