LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-28-2012, 12:49 AM   #1
ar2deetu
Member
 
Registered: Nov 2010
Posts: 31

Rep: Reputation: 1
Unable to view multiple hosted sites offline using apache2 and multiple VirtualHosts


I have several hosted sites (directories) for development purposes only that I work on offline. These are not meant to be viewed from outside my LAN.

I have them set up in /etc/apache2/sites-available/*

In that directory I have set up:
default
site1
site2
site3
etc.

Notice they do not have an ending tld like localhost.

Example of site1:

Code:
<VirtualHost *:80>
        ServerAdmin me@site1
        ServerName site1
        ServerAlias site1
        DocumentRoot /var/www/sites/site1/site
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/sites/site1/site>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/www/logs/site1/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>
The others are the same, just different names.

I had to do some modifications to Hosts file and httpd.conf file to make this work.

Here is what my hosts file looks like:

Code:
127,0,0,1      localhost
127.0.1.1      host
127.0.0.2      site1
127.0.0.3      site2
127.0.0.4      site4
#etc.
/etc/apache2/httpd.conf:
Code:
ServerName  localhost
ServerName  site1
ServerName  site2
ServerName  site3
etc.
When connected to the internet, I can point to site1 with no problem, however, when offline, I can still point to localhost, but not site1 nor the others.

A grep nor a find for localhost really gave me much information as to why localhost works while the others will not work offline.

After reading another post somewhere, I modified the top part of sites-available/site1:

Code:
NameVirtualHost site1
<VirtualHost site1>
    ...
    ...
</VirtualHost>
then changed the Hosts file to make all sites with same server address:
Code:
localhost    127.0.0.1
site1        127.0.0.1
site2        127.0.0.1
site3        127.0.0.1
This also did not work. However, the forum I saw replicating the above idea did not indicate the necessity of viewing files offline.

Appreciate any clues.
 
Old 10-28-2012, 04:49 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,590

Rep: Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799
Quote:
After reading another post somewhere, I modified the top part of sites-available/site1:
<-snip->

then changed the Hosts file to make all sites with same server address:
<-snip->
You should leave those files as they were initially.
Regarding your problem, check /etc/nsswitch.conf and make sure you have "files" before "dns" in the following line:
Code:
hosts:   files dns
Cheers
 
Old 10-28-2012, 07:12 AM   #3
ar2deetu
Member
 
Registered: Nov 2010
Posts: 31

Original Poster
Rep: Reputation: 1
Hi, thanks for the reply bathory.

I tried that after reverting the hosts file and sites-available/site1 files as said.

Still not able to view the files during offline mode.

I modified the file to put dns directly after files and even tried removing the other variables on the same line but no luck. Also did service apach2 reload after each modification.

After reverting that file back to normal, here is the default settings that I had:

Code:
passwd:         compat
group:          compat
shadow:         compat

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis
 
Old 10-28-2012, 01:38 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,590

Rep: Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799
Doh, with this entry in /etc/nsswitch.conf, your system should use the entries in /etc/hosts to resolve the IPs of site1-siteX, regardless of the fact that it's online or offline.
To test, run
Code:
ping siteX
and see if you get the correct IP for siteX.
Also, what is the error you get when trying to visit http://siteX while offline.
 
Old 10-28-2012, 02:02 PM   #5
ar2deetu
Member
 
Registered: Nov 2010
Posts: 31

Original Poster
Rep: Reputation: 1
All sites seem to provide correct address on ping. Example for site2:
Code:
$ ping site2
PING site2 (127.0.0.3) 56(84) bytes of data.
64 bytes from site2 (127.0.0.3): icmp_req=1 ttl=64 time=0.082 ms
64 bytes from site2 (127.0.0.3): icmp_req=2 ttl=64 time=0.073 ms
64 bytes from site2 (127.0.0.3): icmp_req=3 ttl=64 time=0.072 ms
^C
The error visiting site are;

Firefox:
Quote:
Server not found
Chrome:
Quote:
Unable to connecto to the internet
..
Error 106 (net::ERR_INTERNET_DISCONNECTED): The Internet connection has been lost.
 
Old 10-28-2012, 03:18 PM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,590

Rep: Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799
Quote:
All sites seem to provide correct address on ping. Example for site2:

$ ping site2
PING site2 (127.0.0.3) 56(84) bytes of data.
<-snip->
Since the name resolution via the hosts file works, I cannot understand why you cannot access your apache webserver.
Maybe you need to change all these 127.0.0.X IPs to 127.0.0.1, because there is problably a firewall blocking anything except 127.0.0.1.
 
Old 10-28-2012, 06:24 PM   #7
ar2deetu
Member
 
Registered: Nov 2010
Posts: 31

Original Poster
Rep: Reputation: 1
Has anyone else been able to have a setup like mentioned above and be able to view files offline?

In response to bathory's ideas, I tried putting all (sites) in 127.0.0.1, but still doesn't work after apache2 reload.

I even tried to move localhost to 127.0.0.2 and making site1 the only site at the 127.0.0.1 address, do apache2 reload, but still get the same results: localhost still works offline, while the others do not including site1.

So it appears that my system favors localhost over any specific address. Must be something about going through the LAN and coming back to see any other site on my system other than localhost.

Another interesting point is that when I visit siteX, I can still navigate siteX only (as well as localhost) for about 5 minutes after disconnecting, and this includes pages and queries that I hadn't visited before disconnecting.
 
Old 10-29-2012, 04:23 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,590

Rep: Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799Reputation: 1799
This is very strange. Apache should work, regardless being online or not, if you can resolve hostnames through the hosts file.
Perhaps it's avahi not allowing services except for localhost.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to open multiple windows to view multiple docx file with window 2007 installed astromoko Linux - Newbie 2 08-01-2011 09:45 PM
NameVirtualHost *:80 has no virtual hosts apache2 hosting multiple sites without DNS tkmsr Linux - Server 9 06-21-2010 11:27 AM
ubuntu 9.10 apache2 multiple SSL sites eteck Linux - Networking 4 01-12-2010 01:31 AM
Bind configuration for multiple sub-domains on multiple sites JF1980 Linux - Networking 3 08-31-2006 02:28 PM
Multiple Apache Sites, on Multiple IP's, on Same Box?? RickyJ Linux - Software 0 06-19-2003 10:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration