Book Image

Nginx 1 Web Server Implementation Cookbook

By : Dipankar Sarkar
Book Image

Nginx 1 Web Server Implementation Cookbook

By: Dipankar Sarkar

Overview of this book

<p>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.<br /><br /><i>Nginx 1 Web Server Implementation Cookbook</i> 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.<br /><br />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.<br /><br />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.</p> <p>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.</p>
Table of Contents (17 chapters)
Nginx 1 Web Server Implementation Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Easy reloading of Nginx using the CLI


Depending on the system that you have, it will offer one clean way of reloading your Nginx setup

  • Debian based: /etc/init.d/Nginx reload

  • Fedora based: service Nginx reload

  • FreeBSD/BSD: service Nginx reload

  • Windows: Nginx -s reload

All the preceding commands reload Nginx; they send a HUP signal to the main Nginx process. You can send quite a few control signals to the Nginx master process, as outlined in the following table. These let you manage some of the basic administrative tasks:

Signal

Activity

TERM ,INT

Quick shutdown

QUIT

Graceful shutdown

HUP

Reload configuration, gracefully shutdown the worker processes and restart them

USR1

Reopen the log files

USR2

Upgrade the executable on the fly, when you have already installed it

WINCH

Gracefully shutdown the worker process

How to do it...

Let me run you through the simple steps of how you can reload Nginx from the command line.

  1. Open a terminal on your system. Most UNIX-based systems already have fairly powerful terminals, while you can use PuTTY on Windows systems.

  2. Type in ps auxww | grep nginx. This will output something as shown in the following screenshot:

    If nothing comes, then it means that Nginx is not running on your system.

  3. If you get the preceding output, then you can see the master process and the two worker processes (it may be more, depending on your worker_processes configuration). The important number is 3322, which is basically the PID of the master process.

  4. To reload Nginx, you can issue the command kill -HUP <PID of the nginx master process>. In this case, the PID of the master process is 3322. This will basically read the configurations again, gracefully close your current connections, and start new worker processes. You can issue another ps auxww | grep nginx to see new PIDs for the worker processes (4582,4583):

  5. If the worker PIDs do not change it means that you may have a problem while reloading the configuration files. Go ahead and check the Nginx error log.

This is very useful while writing scripts, which control Nginx configuration. A good example is when you are deploying code on production; you will temporarily point the site to a static landing page.