Nginx HTTP Server - Fourth Edition
eBook - ePub

Nginx HTTP Server - Fourth Edition

Martin Fjordvald, Clement Nedelcu

Compartir libro
  1. 348 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Nginx HTTP Server - Fourth Edition

Martin Fjordvald, Clement Nedelcu

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

Make the most of your infrastructure and serve pages faster than ever with Nginx.About This Book• Discover possible interactions between Nginx and Apache to get the best of both worlds• Learn to exploit the features offered by Nginx for your web applications• Get your hands on the most updated version of Nginx (1.13.2) to support all your web administration requirementsWho This Book Is ForThis book is a perfect match to web administrators who are interested in solutions to optimize their infrastructure. Whether you are looking into replacing your existing web server software or integrating a new tool to cooperate with applications that are already up and running, this book is your ideal resource. What You Will Learn• Download and install Nginx on your system• Prepare a basic configuration and test your initial setup• Discover the core functionality of the HTTP module• Make the most of first- and third-party Nginx modules• Set up Nginx to work with PHP, Python, and other applications• Learn how to set up Nginx to work with Apache• Fully replace Apache with Nginx• Optimize your architecture with threads or load balancing• Identify errors in configuration and learn basic troubleshooting techniques• Consult the exhaustive directive and module index for referenceIn DetailNginx is a lightweight HTTP server designed for high-traffic websites, with network scalability as the primary objective. With the advent of high-speed internet access, short loading times and fast transfer rates have become a necessity.This book is a detailed guide to setting up Nginx in ways that correspond to actual production situations: as a standalone server, as a reverse proxy, interacting with applications via FastCGI, and more. In addition, this complete direct reference will be indispensable at all stages of the configuration and maintenance processes. This book mainly targets the most recent version of Nginx (1.13.2) and focuses on all the new additions and improvements, such as support for HTTP/2, improved dynamic modules, security enhancements, and support for multiple SSL certificates. This book is the perfect companion for both Nginx beginners and experienced administrators. For beginners, it will take you through the complete process of setting up this lightweight HTTP server on your system and configuring its various modules so that it does exactly what you need quickly and securely. For more experienced administrators, this book provides different approaches that can help you make the most of your current infrastructure. Nginx can be employed in many situations, whether you are looking to construct an entirely new web-serving architecture or simply want to integrate an efficient tool to optimize your site loading speeds.Style and approachThis book aims to serve as a handy reference of all Nginx first-party modules and directives, allowing the reader to develop their own web configuration more efficiently.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Nginx HTTP Server - Fourth Edition un PDF/ePUB en línea?
Sí, puedes acceder a Nginx HTTP Server - Fourth Edition de Martin Fjordvald, Clement Nedelcu en formato PDF o ePUB, así como a otros libros populares de Computer Science y Client-Server Computing. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2018
ISBN
9781788621977
Edición
4

Module Configuration

The true power of Nginx lies within its modules. The entire application is built on a modular system, and each module can be enabled or disabled at compile time. Some bring up simple functionalities, such as the autoindex module that generates a listing of the files in a directory. Some will transform your perception of a web server (such as the Rewrite module). Developers are also invited to create their own modules. A quick overview of the third-party module system can be found at the end of this chapter.
This chapter covers:
  • The Rewrite module, which does more than just rewrite URIs
  • The SSI module, a server-side scripting language
  • Additional modules enabled in the default Nginx build
  • Optional modules that must be enabled at compile time
  • A quick note on third-party modules

Rewrite module

This module, in particular, brings much more functionality to Nginx than a simple set of directives. It defines a whole new level of request processing that will be explained throughout this section.
Initially, the purpose of this module (as the name suggests) is to perform URL rewriting. This mechanism allows you to get rid of ugly URLs containing multiple parameters, for instance, http://example.com/article.php?id=1234&comment=32—such URLs being particularly uninformative and meaningless for a regular visitor.
Instead, links to your website will contain useful information that indicates the nature of the page you are about to visit. The URL given in the example becomes http://website.com/article-1234-32-US-economy-strengthens.html. This solution is not only more interesting for your visitors, but also for search engines. URL rewriting is a key element to Search Engine Optimization (SEO).
The principle behind this mechanism is simple: it consists of rewriting the URI of the client request after it is received, before serving the file. Once rewritten, the URI is matched against location blocks in order to find the configuration that should be applied to the request. The technique is further detailed in the coming sections.

Reminder on regular expressions

First and foremost, this module requires a certain understanding of regular expressions, also known as regexes or regexps. Indeed, URL rewriting is performed by the rewrite directive, which accepts a pattern followed by the replacement URI.
It is a vast topic; entire books are dedicated to explaining the ins and outs. However, the simplified approach that we are about to examine should be more than sufficient to make the most of the mechanism.

Purpose

The first question we must answer is: what is the purpose of regular expressions? To put it simply, the main purpose is to verify that a string of characters matches a given pattern. The pattern is written in a particular language that allows for defining extremely complex and accurate rules:
String
Pattern
Does it match?
Explanation
hello
^hello$
Yes
The string begins with character h (^h), followed by e, l, l, and then finishes with o (o$).
hell
^hello$
No
The string begins with character h (^h), followed by e, l, l, but does not finish with o.
Hello
^hello$
Depends
If the engine performing the match is case-sensitive, the string doesn't match the pattern.
This concept becomes a lot more interesting when complex patterns are employed, such as one that validates an email addresses: ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$. Validating a well-formed email address programmatically would require a great deal of code, while all of the work can be done with a single regular expression pattern matching.

PCRE syntax

The syntax that Nginx employs originates from the Perl Compatible Regular Expression (PCRE) library, which (if you remember Chapter 2, Basic Nginx Configuration) is a prerequisite for making your own build, unless you disable modules that make use of it. It's the most commonly used form of regular expression, and nearly everything you learn here remains valid for other language variations.
In its simplest form, a pattern is composed of one character, for example, x. We can match strings against this pattern. Does example match the pattern x? Yes, example contains the character x. It can be more than one specific character; the pattern [a-z] matches any character between a and z, or even a combination of letters and digits: [a-z0-9]. In consequence, the pattern hell[a-z0-9] validates the following strings: hello and hell4, but not hell or hell!.
You probably noticed that we employed the characters [ and ]. These are called metacharacters and have a special effect on the pattern. There is a total of 11 metacharacters, and all play a different role. If you want to create a pattern that actually contains one of these characters, you need to escape the character with a \ (backslash):
Metacharacter
Description
^
Beginning
The entity after this character must be found at the beginning:
  • Example pattern: ^h
  • Matching strings: hello, h, hh (anything beginning with h)
  • Non-matching strings: character, ssh
$
End
The entity before this character must be found at the end:
  • Example pattern: e$
  • Matching strings: sample, e, file (anything ending with e)
  • Non-matching strings: extra, shell
. (dot)
Any
Matches any character:
  • Example pattern: hell.
  • Matching strings: hello, hellx, hell5, and hell!
  • Non-matching...

Índice