4

Context: Let's say I have this /etc/apache2/sites-available/000-default.conf file (Debian 9, Apache 2.4):

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html/site1
</VirtualHost>

and that some clients are currently browsing this website, and even some of them are busy downloading a 1 GB file on this website (let's say they're downloading www.example.com/bigfile.zip).

Now I want to add a new VirtualHost and I edit the 000-default.conf file to (and save it):

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html/site1
</VirtualHost>

<VirtualHost *:80>
    ServerName example2.com
    DocumentRoot /var/www/html/site2
</VirtualHost>

Now if I do

service apache2 restart

it will successfully enable the new website example2.com, but also stop all on-going requests from clients for example.com, and it will break for example the downloads in progress.

Question: is there a way to add a new VirtualHost and not interrupt on-going requests (long downloads, etc.) for other VirtualHosts?

Note:

  • I have already read How to reload apache configuration for a site without restarting apache but the question and answer are not precise about what is the consequences "of not restarting" Apache. The same about Can I “reload” Apache2 configuration file without issues?, I'm not sure about what would happen in the case of an ongoing 20-minutes download from a client. Would it wait or not? This question here focuses specifically on adding a new VirtualHost while not breaking the others' requests.

  • I have also ready many similar questions, but this one addresses a precise specific requirement: install a new VirtualHost while not interrupting ongoing requests such as long downloads.

Basj
  • 41,386
  • 99
  • 383
  • 673

1 Answers1

8

Restart == stop, then start.

Instead use apachectl graceful. Graceful lets existing connections complete, then restarts each sub-process one by one, as they are freed. New connections will get the new configuration.

See https://httpd.apache.org/docs/2.4/stopping.html#graceful

Nic3500
  • 8,144
  • 10
  • 29
  • 40
  • What is the difference between `apachectl -k graceful` and `apachectl graceful` @Nic3500? I see both in the doc, but nowhere the `-k` is explained. – Basj Dec 01 '19 at 10:19
  • 1
    Check this: https://superuser.com/questions/777622/what-is-the-apache2ctl-k-flag. `-k` is passed to httpd, no `-k` is handled by `apachectl`. – Nic3500 Dec 03 '19 at 00:26