Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between nginx daemon on/off option?

This is my first web-server administration experience and I want to build docker container which uses nginx as a web-server. In all docker tutorial daemon off; option is put into main .conf file but explanation about it is omitted.

I search on the internet about it and I don't understand what is the difference between daemon on; and daemon off; options. Some people mentioned that daemon off; is for production, why?

Can you explain, what is the difference between this two options, and why I should use daemon off; on production?

like image 723
KopBob Avatar asked Sep 22 '14 09:09

KopBob


People also ask

How do I run nginx in foreground?

In a development environment, using "master_process off", nginx can run in the foreground without the master process and can be terminated simply with ^C (SIGINT). This is somewhat similar to running Apache with an 'X' command-line option. However you should NEVER run nginx in production with "master_process off".

What is the difference between nginx and Docker?

Docker can be classified as a tool in the "Virtual Machine Platforms & Containers" category, while NGINX Unit is grouped under "Web Servers". Some of the features offered by Docker are: Integrated developer tools. open, portable images.


2 Answers

For normal production (on a server), use the default daemon on; directive so the Nginx server will start in the background. In this way Nginx and other services are running and talking to each other. One server runs many services.

For Docker containers (or for debugging), the daemon off; directive tells Nginx to stay in the foreground. For containers this is useful as best practice is for one container = one process. One server (container) has only one service.

Setting daemon off; is also useful if there's a 3rd party tool like Supervisor controlling your services. Supervisor lets you stop/start/get status for bunches of services at once.

I use daemon off; for tweaking my Nginx config, then cleanly killing the service and restarting it. This lets me test configurations rapidly. When done I use the default daemon on;.

like image 67
johntellsall Avatar answered Sep 24 '22 20:09

johntellsall


As mentioned in this SO thread, it appears that "that initial process immediately spawns a master nginx process and some workers, and then quits. Since Docker is only watching the PID of the original command, the container then halts."

Regarding the daemon off directive, it appears that it was originally intended for nginx code development, though is safe for production post version 1.0.9, per the FAQ.

like image 40
johncosta Avatar answered Sep 23 '22 20:09

johncosta