logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Can't get virtual host when disconnected from net
Author
Mike-H



Joined: 29 Dec 2008
Posts: 16

PostPosted: Tue 03 Mar '09 21:26    Post subject: Can't get virtual host when disconnected from net Reply with quote

I have apache running on my laptop and have several virtual hosts defined which work fine for testing purposes. Yesterday, I was out of the office and not connected to any network (neither hard-wired or wifi available) and apache would not serve up my virtual sites. The browser kept trying to go out on the web (which it couldn't) to find it - if I have a local virtual site named mysite, the browser would try to go to www.mysite.com, which of course does not exist, but it wouldn't matter because it couldn't get there anyhow. Later I was at another location and connected to their wireless network, then the browser/apache could find my local virtual site just fine.

Does anyone know why I would have to be connected to a network in order for apache to serve a local virtual site (the hosts file is set to 127.0.0.1 and the httpd-vhosts.conf has the appropriate virtual host information). What do I need to do to connect in this scenario?

Thanks for any and all insights.

Mike
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Tue 03 Mar '09 22:11    Post subject: Reply with quote

What is your Listen directive/s?
What is the main server name?
Back to top
Mike-H



Joined: 29 Dec 2008
Posts: 16

PostPosted: Tue 03 Mar '09 23:06    Post subject: Reply with quote

httpd.conf -->
...
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80
...
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName localhost:80
...

httpd-vhosts.conf has a different server name for each virtual host I have.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Wed 04 Mar '09 13:01    Post subject: Reply with quote

I cannot exactly explain all of it, but I'm going to venture onto a tiny leaf at the end of a really long limb

If you
1. Shut down apache service.
2. cpen a command prompt window
3. cd your way to your Apache bin directory and then type HTTPD and press enter.

I bet you'll see a message about no ServerName, and that Apache is being bound to xxx.xxx.xxx.xxx:80

I'll further bet that IP address is your LAN IP.

So Apache is not listening on 127.0.0.1 in that case, but the LAN IP.
Why when connected to a router? Beats me.

Try adding
Listen 127.0.0.1:80
leaving the original there as well.

See if that helps.
Back to top
Mike-H



Joined: 29 Dec 2008
Posts: 16

PostPosted: Fri 06 Mar '09 17:45    Post subject: Reply with quote

I appreciate your efforts, but this does not help. When I typed httpd in a command prompt window, I actually got "Nothing". I gave it 30 seconds or so and then cancelled it, it didn't seem like it should take that long. If I typed the command while apache is running, then I got an error saying I couldn't have 2 instances of the program running.

I tried adding a second Listen directive and then httpd did give me an error message (but not what I expected from your instructions) and apache wouldn't restart until I took it out. So I guess I can only have one Listen directive in httpd.conf. I would tend to agree that apache is not looking at my local loopback ip address, but why and how do I resolve this? Doesn't Listen 80 just tell it to listen to port 80 on any ip? BTW, "Listen :80" also doesn't work, apache won't start with this set this way, but "Listen 80" does.

If I am away from any kind of lan and want to work on something I can't? This is a development machine running xp pro & apache 2.2.

Thanks for your continued help in trying to educate me.

Mike
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Fri 06 Mar '09 18:21    Post subject: Reply with quote

Mike-H wrote:
I actually got "Nothing".

It would be nice if it said something .. anything .. I agree .. you know the expression "no news is good news", well, that is what you get with Apache when things are working fine.

Yes .. Listen 80 = 0.0.0.0:80
Listen *:80 = 0.0.0.0:80
Listen :80 = Err
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Fri 06 Mar '09 18:46    Post subject: Reply with quote

OK .. I know two things are at play here and I have not seen this result before, but then I've never understood what was meant by "Main host goes away" either, my experience is first vhost dissapears. But I see this as actually happening here if I am understanding all this correctly.

Our first problem is no server name, just from experience I know Apache will give the server a servername of the first lan adapter it sees, but should still bind to all IPs. Here is where main host goes away comes into the picture.

The absolute most common err in vhost config is not adding the main host as the first vhost and then the second, third, so on and so on, and this is where supposedly main host is supposed to dissapear. From what I am understanding here, this is what is happening, why when on a router it begins to work still has me stymied.

So, proposal


# Main Section

Listen 80
ServerName localhost:80

# VHosts

<Virtualhost _default_:80>
Servername localhost
DocumentRoot (the docroot used in main section)
</Virtualhost>

<Virtualhost *:80>
Servername whatever
DocumentRoot /whatever
..
..
</Virtualhost>

<Virtualhost *:80>
Servername whatever2
DocumentRoot /whatever2
..
..
</Virtualhost>

and so an and so on

# Hosts file

127.0.0.1 localhost
127.0.0.1 whatever whatever2

and so an and so on
Back to top
Mike-H



Joined: 29 Dec 2008
Posts: 16

PostPosted: Sat 07 Mar '09 3:14    Post subject: Reply with quote

Well, we "might" be on the right track, but still some bumpy roads ahead. I put this in my httpd.conf file (in Apache2.2/conf directory):

ServerName localhost:80

I put this in httpd-vhosts.conf file (in Apache2.2/conf/extra directory):
<Virtualhost _default_:80>
Servername localhost
DocumentRoot "c:/Apache-htdocs"
</Virtualhost>

Restarted apache, unplugged the network cable, opened a browser window and it couldn't find my page. Next I plugged the network cable in and went to the home page of my virtual site, no problem. Unplugged the cable, clicked on a link in my nav bar (to another page in the same site) and it opened fine. All other pages on that site opened fine. If I closed the browser and reopened it, I could not load that site with the network cable unplugged. As soon as it is plugged in, I can load in an initial page (which page doesn't seem to matter) and any subsequent pages on that site are fine, even when the cable is unplugged. Tried a couple of different virtual sites and in both Firefox and IE with the same results.

I can send my config files if you still want them.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sat 07 Mar '09 22:03    Post subject: Reply with quote

You caught that before I removed I see.
I'm fine with it. I should be able to give them a good going over here tonight or tomorrow.

what was it

al12888 at justmyspace . org
Back to top


Reply to topic   Topic: Can't get virtual host when disconnected from net View previous topic :: View next topic
Post new topic   Forum Index -> Apache