I am wondering how web servers i.e. Nginx, Flask, Django stay alive and wait for requests. And how I can write my own program which stays alive and waits for a request before launching an action.
Asked
Active
Viewed 41 times
1 Answers
1
The short answer for the overwhelming number of cases involving nginx is systemd service. When you install nginx it sets itself up as a systemd service which is configured to start nginx on boot and keep it running.
You can adapt systemd to load and keep your own services (like Flask, etc.) alive and waiting for requests as well. Here is an article that explains the basics.
An alternative to systemd (which is built into most of the Linux systems you would be using on a server) is supervisord. Like systemd, supervisord can be configured to monitor, start, and keep your service running in the background, waiting for a request.

Chase
- 3,009
- 3
- 17
- 23
-
Great, thank you I was aware of daemons but not that webservers were just daemons I thought maybe they were something special. So this clears it up for me! – Jacob B May 29 '20 at 14:47