You are previewing Nginx 1 Web Server Implementation Cookbook.
O'Reilly logo
Nginx 1 Web Server Implementation Cookbook

Book Description

Over 100 recipes to master using the Nginx HTTP server and reverse proxy

  • Quick recipes and practical techniques to help you maximize your experience with Nginx

  • Interesting recipes that will help you optimize your web stack and get more out of your existing setup

  • Secure your website and prevent your setup from being compromised using SSL and rate-limiting techniques

  • Get more out of Nginx by using it as an important part of your web application using third-party modules

  • Full of illustrations and diagrams to help you implement your web needs with Nginx, with focus on practical examples

In Detail

Nginx is an open source high-performance web server, which has gained quite some popularity recently. Due to its modular architecture and small footprint, it has been the default choice for a lot of smaller Web 2.0 companies for use as a load-balancing proxy server. It supports most of the existing back-end web protocols like FCGI, WSGI, and SCGI. This book is for you if you want to have in-depth knowledge of the Nginx server.

Nginx 1 Web Server Implementation Cookbook covers the whole range of techniques that would prove useful for you in setting up a very effective web application with the Nginx web server. It has recipes for lesser-known applications of Nginx like a mail proxy server, streaming of video files, image resizing on the fly, and much more.

The first chapter of the book covers the basics that would be useful for anyone who is starting with Nginx. Each recipe is designed to be independent of the others.

The book has recipes based on broad areas such as core, logging, rewrites, security, and others. We look at ways to optimize your Nginx setup, setting up your WordPress blog, blocking bots that post spam on your site, setting up monitoring using munin, and much more.

Nginx 1 Web Server Implementation Cookbook makes your entry into the Nginx world easy with step-by-step recipes for nearly all the tasks necessary to run your own web application.

A practical guide for system administrators and web developers alike to get the best out of the open source Nginx web server

Table of Contents

  1. Nginx 1 Web Server Implementation Cookbook
    1. Nginx 1 Web Server Implementation Cookbook
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    7. 1. The Core HTTP Module
      1. Introduction
      2. Installing new modules and compiling Nginx
        1. How to do it...
        2. There's more...
      3. Running Nginx in debug mode
        1. How to do it...
        2. There's more...
      4. Easy reloading of Nginx using the CLI
        1. How to do it...
      5. Splitting configuration files for better management
        1. How to do it...
      6. Setting up multiple virtual hosts
        1. How to do it...
        2. How it works...
        3. There's more...
      7. Setting up a default catch-all virtual host
        1. How to do it...
        2. How it works...
      8. Using wildcards in virtual hosts
        1. How to do it...
        2. How it works...
      9. Setting up the number of worker processes correctly
        1. How to do it...
        2. How it works...
        3. There's more...
      10. Increasing the size of uploaded files
        1. How to do it...
        2. There's more...
      11. Using dynamic SSI for simple sites
        1. How to do it...
          1. How it works...
          2. There's more...
        2. Adding content before and after a particular page
          1. How to do it…
        3. Enabling auto indexing of a directory
          1. How to do it...
          2. How it works...
        4. Serving any random web page from a directory
          1. How to do it...
          2. How it works...
        5. Serving cookies for identifying and logging users
          1. How to do it…
          2. How it works...
          3. There's more...
        6. Re-encoding the response to another encoding
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Enabling Gzip compression on some content types
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Setting up 404 and other error pages
          1. How to do it...
          2. How it works...
    8. 2. All About Rewrites: The Rewrite Module
      1. Introduction
      2. Setting up a simple redirect
        1. How to do it...
        2. How it works...
        3. There's more...
      3. Using variables in your rewrite
        1. How to do it...
        2. How it works...
        3. There's more...
      4. Using cookies for your rewrites
        1. How to do it...
        2. How it works...
      5. Using browser agents for your rewrites
        1. How to do it...
        2. How it works...
      6. Using rate limits as a condition for rewrites
        1. How to do it...
        2. How it works...
        3. There's more...
      7. Blocking requests based on HTTP referrers
        1. How to do it...
        2. How it works...
      8. Serving maintenance page when deploying
        1. How to do it...
          1. How it works...
      9. Setting up a WordPress site with static file serving
        1. How to do it...
        2. How it works...
        3. There's more...
      10. Setting up a Drupal site with static file serving
        1. How to do it...
        2. How it works...
        3. There's more...
      11. Setting up a Magento site with static file serving
        1. How to do it...
        2. How it works...
      12. Converting your Apache's .htaccess into Nginx rewrites
        1. How to do it...
        2. How it works...
        3. There's more...
      13. Using maps to make configurations cleaner
        1. How to do it...
        2. How it works...
        3. There's more…
    9. 3. Get It All Logged: The Logging Module
      1. Introduction
      2. Setting up error log path and levels
        1. How to do it...
        2. How it works...
        3. There's more...
      3. Logging it like Apache
        1. How to do it...
        2. How it works...
      4. Disabling logging of 404 in error logs
        1. How to do it...
        2. How it works...
      5. Using different logging profiles in the same setup
        1. How to do it...
        2. How it works...
        3. There's more...
      6. Enabling a log file cache
        1. How to do it...
        2. How it works...
      7. Utilizing separate error logs per virtual host
        1. How to do it...
        2. How it works...
        3. There's more...
      8. Setting up log rotation
        1. How to do it...
        2. How it works...
      9. Enabling remote logging with syslog-ng
        1. How to do it...
        2. How it works...
      10. Setting up your custom logs for easy parsing
        1. How to do it...
        2. How it works...
        3. There's more...
    10. 4. Slow Them Down: Access and Rate Limiting Module
      1. Introduction
      2. Limiting requests for any given session
        1. How to do it...
        2. How it works...
        3. There's more...
      3. Blocking and allowing access using IP
        1. How to do it...
        2. How it works...
        3. There's more....
      4. Setting up simple rate limiting for a download directory
        1. How to do it...
        2. How it works...
        3. There's more...
      5. Rate limiting search engine bots
        1. How to do it...
        2. How it works...
        3. There's more....
      6. Setting up GeoIP using the MaxMind country database
        1. How to do it...
          1. How it works...
      7. Using the GeoIP module to set up access and rate control
        1. How to do it...
        2. How it works...
    11. 5. Let's be Secure: Security Modules
      1. Introduction
      2. Setting up HTTP auth for access control
        1. How to do it...
        2. How it works...
      3. Generating a secure link for files
        1. How to do it...
        2. How it works...
      4. Setting up HTTPS for a simple site
        1. How to do it...
        2. How it works...
        3. There's more...
      5. Using non standard error codes for debugging SSL setup
        1. How to do it...
        2. How it works...
      6. Using wildcard certificates with multiple servers
        1. How to do it...
        2. How it works...
      7. Using Nginx SSL variables for rewrite rules
        1. How to do it...
        2. How it works...
        3. There's more...
    12. 6. Setting Up Applications: FCGI and WSGI Modules
      1. Introduction
      2. Setting up a PHP FCGI site
        1. How to do it...
        2. How it works...
        3. There's more...
      3. Setting up a Python site using uWSGI
        1. How to do it...
        2. How it works...
        3. There's more...
      4. Modifying FCGI timeouts
        1. How to do it...
        2. How it works...
      5. Utilizing FCGI cache to speed it up
        1. How to do it...
        2. How it works...
      6. Using multiple FCGI backends
        1. How to do it...
        2. How it works...
    13. 7. Nginx as a Reverse Proxy
      1. Introduction
      2. Using Nginx as a simple reverse proxy
        1. How to do it...
        2. How it works...
      3. Setting up a rails site using Nginx as a reverse proxy
        1. How to do it...
          1. How it works...
      4. Setting up correct reverse proxy timeouts
        1. How to do it...
        2. How it works...
      5. Setting up caching on the reverse proxy
        1. How to do it...
        2. How it works...
        3. There's more...
      6. Using multiple backends for the reverse proxy
        1. How to do it...
        2. How it works...
      7. Serving CGI files using thttpd and Nginx
        1. How to do it...
          1. How it works...
      8. Setting up load balancing with reverse proxy
        1. How to do it...
          1. How it works...
          2. There's more...
      9. Splitting requests based on various conditions using split-clients
        1. How to do it...
        2. How it works...
    14. 8. Improving Performance and SEO Using Nginx
      1. Introduction
      2. Setting up TCP options correctly for optimizing performance
        1. How to do it...
        2. How it works...
      3. Reducing the keep-alives to free up Nginx workers
        1. How to do it...
        2. How it works...
      4. Using Memcached as the cache backend
        1. How to do it...
        2. How it works...
      5. Configuring the right event model and file limits
        1. How to do it...
        2. How it works...
      6. Setting max-age expiry headers for client-side caching
        1. How to do it...
        2. How it works...
      7. Blocking scrapers, bots, and spiders to save bandwidth
        1. How to do it...
        2. How it works...
      8. Redirection of www to non-www domain for SEO
        1. How to do it...
        2. How it works...
      9. Removing all white space from response
        1. How to do it...
          1. How it works...
      10. Setting up server status for monitoring
        1. How to do it...
          1. How it works...
      11. Setting up Munin for 24x7 Nginx monitoring
        1. How to do it...
        2. How it works...
      12. Enabling GZIP pre-compression
        1. How to do it...
          1. How it works...
      13. Preventing hotlinking using Nginx
        1. How to do it...
        2. How it works...
      14. Using embedded Perl to minify JavaScript files
        1. How to do it...
        2. How it works...
        3. There's more...
      15. Using embedded Perl to minify CSS files
        1. How to do it...
        2. How it works...
      16. Using embedded Perl to serve sitemaps (SEO)
        1. How to do it...
        2. How it works...
      17. Setting up Boost module on Drupal with Nginx
        1. How to do it...
        2. How it works...
      18. Setting up streaming for Flash files
        1. How to do it...
        2. How it works...
      19. Utilizing the 1x1 GIF serving module to do offline processing
        1. How to do it...
        2. How it works...
    15. 9. Using Other Third-party Modules
      1. Introduction
      2. Setting up an IMAP/POP3 proxy server
        1. How to do it...
        2. How it works...
      3. Setting up authentication for mail services
        1. How to do it...
        2. How it works...
      4. Setting up SSL for mail authentication
        1. How to do it...
        2. How it works...
      5. Using Nginx as a WEBDAV reverse proxy
        1. How to do it...
        2. How it works...
      6. Dynamic image resizing using Nginx
        1. How to do it...
          1. How it works...
          2. There's more...
      7. Replacing and searching text in Nginx response
        1. How to do it...
        2. How it works...
      8. Assembling ZIP files on the fly
        1. How to do it...
        2. How it works...
      9. Using Nginx as a HTTP publish-subscribe server
        1. How to do it...
        2. How it works...
        3. There's more...
      10. Transforming XML responses using XSLT templates
        1. How to do it...
        2. How it works...
      11. Setting up Etags for static content
        1. How to do it...
        2. How it works...
      12. Easy logging of page load times
        1. How to do it...
        2. How it works...
      13. Streaming of MP4/H.264 files
        1. How to do it...
        2. How it works...
      14. Setting up SCGI sites
        1. How to do it...
        2. How it works...
      15. Setting up expiring links
        1. How to do it...
        2. How it works...
    16. 10. Some More Third-party Modules
      1. Introduction
      2. Configuring a fair load balancing
        1. How to do it…
        2. How it works…
        3. There's more…
        4. See also
      3. Setting up health checks for backend servers
        1. How to do it…
        2. How it works…
      4. Tracking and reporting file upload progress
        1. How to do it…
        2. How it works…
      5. Generating circles for round edges using Nginx
        1. How to do it…
        2. How it works…
      6. Running Python using Phusion Passenger
        1. How to do it…
        2. How it works…
        3. See also
      7. Generating graphs directly from RRDtool in Nginx
        1. How to do it…
        2. How it works…
      8. Using Google performance tools
        1. How to do it…
        2. How it works…
      9. Serving content directly from GridFS
        1. How to do it…
        2. How it works…
      10. Configuring Basic HTTP auth using PAM
        1. How to do it…
        2. How it works…
      11. Configuring Basic HTTP auth using Kerberos
        1. How to do it…
        2. How it works…
        3. See also