T
T
therhino2015-03-12 21:46:07
Nginx
therhino, 2015-03-12 21:46:07

Do I understand how a web server works correctly?

I'm just starting to deal with servers, in particular I'm interested in nginx . The documentation says:

Nginx has one main and several worker processes. The main task of the main process is to read and validate configuration and manage worker processes. Worker processes perform the actual processing of requests.

If I for example use Unicorn (or something else) with it.
  1. By Nginx's worker process, in this case, do you mean a running Unicorn or something else?
  2. How correctly do I understand the work? For example, nginx is running on port 80 and accepting requests - it gives the static itself, the rest of the requests are proxied by Unicorn. For example, the nginx configuration says worker_processes 2; and in the Unicorn setting it says that there are 3 worker processes, that is, 2 Unicorns are running at the same time, each of which has 3 worker processes, right? Nginx itself decides which of the Unicorns to send the request, and accordingly Unicorn itself decides which of its worker workers to transfer it to? Approximately this scheme

Please correct me if I'm wrong. I will be very grateful!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
ldv, 2015-03-12
@ldvldv

For example, the nginx configuration says worker_processes 2

there will be 1 master process and 2 workers = 3 nginx
askubuntu.com/questions/399431/how-many-nginx-proc...
there will be 1 master process and 3 workers = 4 unicorn
varanecas.com/blog/unicorn-procline
after a request is received on port 80, nginx passes it to one of its worker processes, which in turn proxies it (for example, via a socket) to unicorn worker processes.

P
polozad, 2015-03-17
@polozad

Nginx starts as a master process that forks the number of workers described in the config. A worker is a child independent process, in each of which one thread processes data. In total, if you have two workers specified in the config, nginx essentially works in three processes, but the web server logic is processed by just two.
Further, about unicorn - this is the backend. Its existence has nothing to do with nginx at all.
A typical scheme - nginx starts with the number of workers equal to the number of processors in the system. Further, it hangs on port 80/443 and listens. It processes incoming connections according to the logic of configs. That is, either he gives something away, or he proxies further to the backend, providing the necessary headers. The backend is already, for example, unicorn, and nginx doesn't really care if it's alive or not, it will show 200 in a normal situation and 504 if unicorn falls off.

P
Puma Thailand, 2015-03-12
@opium

The nginx worker has nothing to do with unicorn, consider them as independent things

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question