10
Nginx HTTP Server Adopt Nginx for your web applications to make the most of your infrastructure and serve pages faster than ever element Nedelcu [ ] e PUBLISHING BIRMINGHAM - MUMBAI

Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Embed Size (px)

Citation preview

Page 1: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Nginx HTTP Server

Adopt Nginx for your web applications to make the mostof your infrastructure and serve pages faster than ever

element Nedelcu

[ ] ~men~e~eri~c::i~lI~dCePUBLISHING

BIRMINGHAM - MUMBAI

Page 2: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Preface

Table of Contents1

Chapter 1: Preparing your Work EnvironmentSetting up a terminal emulator

Finding and downloading PuTTYCreating a sessionWorking with PuTTY and the shell

Basic shell commandsFile and directory managementUser and group management

Superuser accountUser accountsGroup management

Programs and processesStarting an applicationSystem servicesProcess management

Discovering the Linux filesystemDirectory structureSpecial files and devices

Device typesPseudo devicesMounting a storage device

Files and inodesEXT3 filesystem specificationsFilenamesInodesAtime. ctime, and mtimeSymbolic and hard links

File manipulationReading a file

7788

10111115151517

18181920

222225252627282929293031

3233

Page 3: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Table of Contents

Editing a fileCompression and archiving

System administration toolsRunning a command as Superuser

Su commandSudo command

System verification and maintenanceDisk FreeDisk UsageFree memory

Software packagesPackage managersDownloading and installing packages manuallyBuilding from source

Files and permissionsUnderstanding file permissionsDirectory permissionsOctal representationChanging permissionsChanging ownership and group

SummaryChapter 2: Downloading and Installing Nginx

Setting up the prerequisitesGCC - GNU Compiler CollectionPCRE libraryzlib libraryOpenSSL

Downloading NginxWebsites and resourcesVersion branchesFeaturesDownloading and extracting

Configure optionsThe easy wayPath optionsPrerequisites optionsModule options

Modules enabled by defaultModules disabled by default

Miscellaneous optionsConfiguration examples

About the prefix switchRegular HTTP and HTTPS serversAll modules enabled

[ ii ]

34353737373839393940

40404142434343444445

464747484950505151525354555556585959606162636364

Page 4: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Mail server proxy

Build configuration issuesMake sure you installed the prerequisitesDirectories exist and are writable

Compiling and installingControlling the Nginx service

Daemons and servicesUser and groupNginx command-line switchesStarting and stopping the daemonTesting the configurationOther switches

Adding Nginx as a system serviceSystem V scriptsWhat is an init script?Creating an init script for NginxInstalling the script

Debian-based distributionsRed Hat-based distributions

Summary

Chapter 3: Basic Nginx ConfigurationConfiguration file syntax

Configuration DirectivesOrganization and inclusionsDirective blocksAdvanced language rules

Directives accept specific synlaxesDiminutives in directive valuesVariablesString values

Base module directivesWhat are base modules?Nginx process architectureCore module directivesEvents moduleConfiguration module

A configuration for your profileUnderstanding the default configurationNecessary adjustmentsAdapting to your hardware

Testing your serverCreating a test server

Table ofContents

6465656566676768686969707171737375767677

79798081838484858686868787889395959596979999

~---~.~-------- [iii] --------------

Page 5: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Table ofContents

Performance testsHttperfAutobenchOpenWebload

Upgrading Nginx gracefullySummary

Chapter 4: HTTP ConfigurationHTTP Core module

Structure blocksModule directives

Socket and host configurationPaths and documentsClient requestsMIME TypesLimits and restrictionsFile processing and cachingOther directives

Module variablesRequest headersResponse headersNginx generated

The Location blockLocation modifierSearch order and priority

Gase 1:Gase 2:Gase 3:

Summary

Chapter 5: Module ConfigurationRewrite module

Reminder on regular expressionsPurposePGRE syntaxQuantifiersGaptures

Internal requestserror_pageRewriteInfinite loopsServer Side Includes (551)

Conditional structureDirectivesCommon rewrite rules

100101102103

105106107107108109110114117121123125127130130131132133133136137138138

139141141142142142144145

146147148149150

151153156

-------------- [iv] --------------

Page 6: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Performing a searchUser profile pageMultiple parametersWikipedia-likeNews website articleDiscussion board

551 moduleModule directives and variablesSSI Commands

File includesWorking with variablesConditional structureConfiguration

Additional modulesWebsite access and logging

IndexAutoindexRandom indexLog

Limits and restrietionsAuth_basic moduleAccessLimit zoneLimit request

Content and encodingEmpty GIFFLVHTTP headersAdditionSubstitutionGzip filterGzip staticCharset filterMemcachedImage filterXSLT

About your visitorsBrowserMapGeoGeolPUserlD filterRefererRealiP

SSL and securitySSLSetting up an SSL certificateSecure link

Table ofContents

156156156157157157

157158160160162163163

164164164165166166

168168168169169

170170171171172172173175175176178179

179179180180181181182183

183183185186

[v] --------------

Page 7: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Table ofContents

Other miscellaneous modulesStub statusGoogle-perftoolsWebDAV

Third-party modulesSummary

Chapter 6: PHP and Python with NginxIntroduction to FastCGI

Understanding the mechanismCommon Gateway Interface (CGI)Fast Common Gateway Interface (FastCGI)Main directivesFastCGI cachingUpstream blocks

Module syntaxServer directive

PHP with NginxArchitecturePHP·FPMSetting up PHP and PHP-FPM

Downloading and extraetingPatchingRequirementsBuilding PHPPost-install configurationRunning and controlling

Nginx configurationPython and Nginx

DjangoSetting up Python and Django

PythonDjangoStarting the FastCGI process manager

Nginx configurationSummary

Chapter 7: Apache and Nginx TogetherNginx as reverse proxy

Understanding the issueThe reverse proxy mechanismAdvantages and disadvantages

Nginx Proxy moduleMain directives

187187187188

189190191192192193194195201204205206207207208208208209209209210210

211212212213213213214

215215217217218219220221222

------------- [vi] --------------

Page 8: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Caching, buffering, and temporary filesLimits, timeouts, and errorsOther directivesVariables

Configuring Apache and NginxReconfiguring Apache

Configuration overviewResetting the port numberAccepting local requests only

Configuring NginxEnabling proxy optionsSeparating content

Advanced configurationAdditional steps

Forwarding the correct IP addressSSL issues and solutionsServer control panel issues

SummaryChapter 8: From Apache to Nginx

Nginx versus ApacheFeatures

Core and functioningGeneral functionality

Flexibility and communityPerformanceUsageConclusion

Porting your Apache configurationDirectivesModulesVirtual hosts and configuration sections

Configuration sectionsCreating a virtual host

htaccess filesReminder on Apache .htaccess filesNginx equivalence

Rewrite rulesGeneral remarks

On the locationOn the syntaxRewriteRule

Table 0/ Contents

225228229230230231231231232

233233235

237238238239239240241241242242243

244244245246246246249250250251254254255257257257258259

-------------- (vii] --------------

Page 9: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Table o[ Con tents

WordPressMediaWikivBulietin

SummaryAppendix A: Directive Index

Appendix B: Module ReferenceAccessAddition*Auth_basic moduleAutoindexBrowserCharsetCoreDAV*Empty GIFEventsFastCGIFLV*GeoGeo IP*Google-perftools*GzipGzip Static*HeadersHTTP CoreImage Filter*IndexLimit RequestsLimit ZoneLogMapMemcachedProxyRandom index*ReallP*RefererRewriteSecure Link*SSISSL*

259261262263265287287287288288288288289289289289290290290290291291291291292292292292293293293293294294294294295295295295

-------------[viii]-------------

Page 10: Nginx HTTP Server - Willkommen — Verbundzentrale … configuration Python and Nginx Django Setting up Python and Django Python Django Starting the FastCGI process manager Nginx configuration

Stub status*Substitution*UpstreamUser 10XSLT*

Appendix C: TroubleshootingGeneral tips on troubleshooting

Checking access permissionsTesting your configurationHave you reloaded the service?Checking logsInstall issues403 Forbidden custom error pageLocation block prioritiesIf block issues

Inefficient statementsUnexpected behavior

Index

Table ofContents

296296296296297299299299300300300301301302303303304

305

-------------- [ix] --------------