简体   繁体   中英

Add or remove or reload a specific VirtualHost without restarting Apache (and having other VirtualHosts' requests interrupted)

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 VirtualHost s?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM