Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx - Can I add a new virtual host without restarting the server?

Can I set a new virtual host using the server object in the nginx.conf configuration file, without restarting the server (and without closing the active connections)?

Thanks

like image 849
Mark Avatar asked Oct 30 '11 06:10

Mark


People also ask

Do I need to restart nginx after config change?

You need to reload or restart Nginx whenever you make changes to its configuration. The reload command loads the new configuration, starts new worker processes with the new configuration, and gracefully shuts down old worker processes.

Do I need to restart nginx?

NGINX is popular web hosting and reverse proxy software for Linux systems. Like many other applications and services, it occasionally needs restarted. Restarting is especially common when making updates to configuration files. You'll always need to restart or reload NGINX for the changes to take effect.

Does nginx reload cause downtime?

the reload command of nginx is for reload of configuration files ,and during the progress , there's no downtime of the service .


2 Answers

Yes you can.

nginx -s reload

Or you can send SIGHUP to the nginx process.

sudo kill -HUP [nginx's pid]

like image 70
Timofey Stolbov Avatar answered Sep 19 '22 18:09

Timofey Stolbov


You can Load New Configuration Using Signals. It will

  1. Read and test a new configuration. If the configuration invalid then do nothing.
  2. When valid, start new processing workers with new configuration. Attach new workers to port listening, log, etc.
  3. Detach old workers from listeners.
  4. Gracefully shutdown old workers.

You can even Upgrade To a New Binary On The Fly. See the same doc.

To perform the reload, send the reload signal:

nginx -s reload
like image 23
Dmitry Kaigorodov Avatar answered Sep 19 '22 18:09

Dmitry Kaigorodov