Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

and the crash of one process does not affect other processes. However, they
cannot handle as many clients because the creation and destruction of all of
those processes creates a lot of processor overhead and requires a large
amount of memory. Thread-based servers are great because requests can share
memory, making them more efficient and thereby able to serve more requests
more quickly. However, a crash in one thread could bring down the entire
server.


What makes Nginx different is that it uses an event-driven architecture to
handle requests. Instead of starting a new process or a new thread for each
request, in an event-driven architecture, the flow of the program is controlled
by events, some form of message sent from another process or thread. Here,
you have a process that runs as a “listener” or an “event detector” that waits
for a request to come in to the server. When the request arrives, instead of a
new process starting, the listener sends a message to a different part of the
server, called an event handler, which then performs a task. The simplified
outcome of serving web pages this way is that less processor time and less
memory are needed. There are some significant difficulties inherent in using
this method, not the least of which can be greater code complexity, which can
make fixing bugs, adding features, and understanding code as a newcomer (or
even a returning veteran of the same codebase who has been away from it for
a little while) more difficult.


Nginx is designed to scale well from one small, low-powered server up to
large networks involving many servers.


For configuration, Nginx uses a system of virtual hosts, similar to Apache,
and a similar set of configuration files. The differences are semantic and not
terribly difficult. You can create URL rewrites in Nginx using a rather
different syntax. In addition, there is nothing similar to Apache’s rewrite
conditions. Occasional blog posts and web tutorials give some workarounds
to handle some of the common forms, but if this is something you do often,
you might not want to use Nginx.


One file that many people use and love in Apache is .htaccess. There is
nothing similar to that in Nginx, so if you need the ability to make changes to
rewrites or configurations without restarting the server, you are out of luck.
This is probably the primary reason that you don’t see shared hosting offering
Nginx.


Finally, another well-documented option is to use both Apache and Nginx
together, with Apache handling any and all dynamic requests and Nginx
handling all static requests. This is faster and lighter than using Apache alone
but comes with the burden of added complexity and the increased potential

Free download pdf