3

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

<VirtualHost 123.45.67.89:80> ServerAdmin [email protected] 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.local? (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.

2
  • Have you set ServerRoot to anything other than the default /etc/apache2? Commented May 4, 2011 at 13:53
  • @eduardo-ivanec The ServerRoot in the /etc/apache2/apach2.conf is commented out (by default). Is it gonna be an issue? Commented May 4, 2011 at 14:07

2 Answers 2

0

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 
3
  • I update the question to include some more info. Commented May 4, 2011 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. Commented May 4, 2011 at 14:31
  • Try disabling the default site in sites-enabled and see if it changes the way it starts after boot Commented May 4, 2011 at 14:45
0

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.

1
  • 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. Commented May 4, 2011 at 20:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.