Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Just setup an apache webserver in Debian 6 and add this following virtualhost:

<VirtualHost 123.45.67.89:80> 
   ServerAdmin admin@mysite.com 
   ServerName mysite.com 
   ServerAlias www.mysite.com 
   DocumentRoot /srv/www/mysite.com/public_html 
   ErrorLog /srv/www/mysite.com/logs/error.log 
   CustomLog /srv/www/mysite.com/logs/access.log combined 
</VirtualHost>

And the I enable it (the default vhost is also enabled):

a2ensite mysite.com 

Reload:

/etc/init.d/apache2 reload 

My /etc/hosts is as follow:

127.0.0.1      localhost.localdomain   localhost 
123.45.67.89   myhost.mysite.com       myhost

And then I tested by accessing mysite.com and www.mysite.com. Everything works fine at this point.

The problem is, every time I reboot, I can no longer access my site anymore. Doesn't work with mysite.com and www.mysite.com.

After fiddling around and monitoring the log, it seems that after reboot apache always look for files in /etc/apache2/htdocs. Which is not specified in any config files.

The only way I can make it work again after reboot is by issuing /etc/init.d/apache2 reload.

Any suggestions?

Thanks in advance.


[UPDATE 1]

This is the content of /etc/apache2/sites-enabled/

lrwxrwxrwx 1 root root 26 May  4 13:41 000-default -> ../sites-available/default
lrwxrwxrwx 1 root root 29 May  4 11:12 mysite.com -> ../sites-available/mysite.com

And this is the last line of the /var/log/apache2/error.log right after boot-up

[Wed May 04 13:43:17 2011] [notice] caught SIGTERM, shutting down
[Wed May 04 13:43:37 2011] [notice] Apache/2.2.16 (Debian) configured -- resuming normal operations

How can I make sure that apache is starting on boot? Issuing:

update-rc.d apache2  defaults

Will output:

update-rc.d: using dependency based boot sequencing

Should I try to put /etc/init.d/apache2 reload inside */etc/rc.loca*l? (just to make sure it's executed)


[UPDATE 2]

I just did something that I think fixed the problem. What I did was change back:

NameVirtualHost 123.45.67.89:80

to

NameVirtualHost *:80

And then change every vhost files as well from:

<VirtualHost 123.45.67.89:80>

to

<VirtualHost *:80>

After that it just works. I tried to reboot 2-3 times and still works. I don't know if this is a good setting though.

The reason I use IP address in the first place is because the wiki/doc/library of my VPS provider said so.

So I guess I'll close the topic for now and do more testing.

Thanks guys.

share|improve this question
    
Have you set ServerRoot to anything other than the default /etc/apache2? –  Eduardo Ivanec May 4 '11 at 13:53
    
@eduardo-ivanec The ServerRoot in the /etc/apache2/apach2.conf is commented out (by default). Is it gonna be an issue? –  nightrod May 4 '11 at 14:07
add comment

2 Answers 2

Can you post the following:

Contents of /etc/apache2/sites-enabled/

Contents of /var/log/apache2/error.log during the reboot (once you've booted in the bottom of the log should have the startup logs.

A very very low level, not really fixing the problem solution would be to just

put /etc/init.d/apaceh2 reload inside /etc/rc.local.

Finally are you sure that apache is starting on boot? Run the following

update-rc.d apache2  defaults
share|improve this answer
    
I update the question to include some more info. –  nightrod May 4 '11 at 14:03
    
And I think the apache is restarted properly after reboot. I checked it by issuing htop right after reboot and I saw a bunch of apache2 processes. –  nightrod May 4 '11 at 14:31
    
Try disabling the default site in sites-enabled and see if it changes the way it starts after boot –  Pratik Amin May 4 '11 at 14:45
add comment

The solution's interesting, nightrod.

My conjecture is that at the time Apache starts your IP is still not set - either because of eth* being down or because you're using static DHCP and are waiting for an answer from the DHCP server, etc. So Apache (conjecture follows) doesn't load either the VirtualHost definition or the NameVirtualHost directive as the IP isn't currently configured on the server and so it can't possibly ever match. I'm guessing it still binds the port as *:80 because the loopback device is available and so it can reasonably start. The result is that after bringing eth* up you had apache listening but no VirtualHost configured.

share|improve this answer
    
It's very possible that it's indeed the case. As for using the asterisk(*), I myself don't know what's the best practice here. Because on my VPS documentation, it's clearly stated to use my public IP. Nobody seems to report anything. –  nightrod May 4 '11 at 20:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.