Nginx HTTP Server - Fourth Edition
eBook - ePub

Nginx HTTP Server - Fourth Edition

Martin Fjordvald, Clement Nedelcu

Partager le livre
  1. 348 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Nginx HTTP Server - Fourth Edition

Martin Fjordvald, Clement Nedelcu

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

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.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Nginx HTTP Server - Fourth Edition est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Nginx HTTP Server - Fourth Edition par Martin Fjordvald, Clement Nedelcu en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Client-Server Computing. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781788621977

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...

Table des matiĂšres