![]() The master process is basically a load balancer that distribute the work across the workers. When nginx sends a request to it the master process accepts it and forwards it to one of the worker processes. It actually has a master process and many worker processes. It's a process manager so it's more than just a running program that can accept requests from nginx. It runs as a separate process on the server and we can instruct nginx to pass every PHP request to php-fpm which will run the Laravel app and return the HTML or JSON response to nginx. ![]() This is the component that implements the FastCGI protocol and connects nginx with our Laravel application. php-fpm is not a protocol or an interface but an actual executable program. We're going to use both of them later.įpm stands for FastCGI Process Manager. It also implements multiplexing but this is not the topic of our discussion.įastCGI can be implemented over unix sockets or TCP. Instead, it has persistent processes which can handle multiple requests by its lifetime so it reduces the CPU overhead of creating/destroying processes and switching between them. ![]() FastCGI does this by dropping the "one-process-per-request" model. It's built on top of CGI and as its name suggests it's faster. The CPU also needs to switch context pretty often which becomes a costly task when the load is big on the server.įastCGI is also a protocol. The cost of creating and destroying processes is quite high. The main advantage of this model is that it's pretty simple but the disadvantage is that it's pretty resource intensive and hard to scale when there's a high traffic. If 1000 requests come in it creates 1000 processes and so on. It means that when a request comes in to the web browser it creates a new process to execute the php script: It can be implemented in any language that supports network sockets.ĬGI uses a "one-process-per-request" model. It can even be a C++ or Delphi program it doesn't need to be a classic "scripting" language. It's platform and language-independent so the script can be written in PHP, python, or anything. CGI specificationĬGI gives us a unified way to run scripts from web servers to generate dynamic content. The Common Gateway Interface (CGI) is a simple interface for running external programs, software or gateways under an information server in a platform-independent manner. The original specification defines CGI like this: As the name suggests, it's not a package or library. This is what CGI does.ĬGI stands for Common Gateway Interface. So we need something that connects the web server with our PHP scripts. And it's not only true for PHP it doesn't know what to do with a Ruby or Perl script either. Let's fix this! CGI, FastCGI, php-fpmĪs I said, nginx doesn't know how to run and interpret PHP scripts. So it returns the content of the file as plain text. If I add an index.php to the root folder and try to request it, I get the following response: Once again, it's not production-ready and it's not optimized at all. That's it! This is bare minimum nginx configuration to serve static content. When the browser parser the HTML and sends a request for the style.css the request looks like this: which also exists since it lives inside the root folder. Which, if you remember, exists so it can return it to the client. So if you write index.html it means /var/inside the root folder. Every filename after this directive will refer to this path. The root directive defines the root folder of the given site. So with contexts we can describe the "hierarchy" of things: Inside the server context we can have location context (but we don't have right now) which refers to specific URLs on this site. So if we have 10 sites on this server each will log to the /var/log/nginx/access.log file which is obviously not good, but it's okay for now.Īnother context is server which refers to one specific site. They define a scope where we can configure scope-related things. http, server, location, and events are the contexts in this config. In an nginx config there are two important terms, context, and directive:Ĭontext is similar to a "scope" in a programming language. This is not a production config! It's only for demo purposes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |