Reload effect and working process of Nginx reopen

Source: Internet
Author: User
Tags openssl library nginx server automake

Http://www.iigrowing.cn/nginx-reopen-reload-zuo-yong-ji-gong-zuo-guo-cheng.html

Reload effect and working process of Nginx reopen

2012-12-05 Categories:nginx Author:Sch

Original articles, reproduced please specify the source and retain the original URL address

A About Nginx

Nginx ("Engine X") is a high-performance HTTP and reverse proxy server written by the Russian Igor Sysoev (Sesoyev). Nginx has been in Russia's largest portal ──rambler Media (www.rambler.ru) for 4 years, while Russia more than 20% of the virtual host platform using Nginx as a reverse proxy server. In China, there have been Sina blog, Sina Podcast, Sohu Pass, NetEase news, NetEase Blog, Jinshan Carefree net, Kimshan word bully, Xiaonei, Yupoo album, Watercress, Thunder look at a number of websites, channels using Nginx server.

Nginx advantages and the introduction of the network is very much, we have to find out their own

http://www.nginx.org/Download

http://www.nginx.com/Documentation and support

These two sites are Nginx's own website, which can download programs and view documents. However, it seems that nginx documents are generally not very full.

Two Nginx Installation

Use CentOS as an example to install Nginx for reference, see the Nginx website for details

The requirements for compiling nginx are as follows:

Disk space: You need to ensure that there is more than 10MB of disk space. After installation, the Nginx will occupy about 4MB of disk space, and the actual disk space requirements will vary depending on the compilation settings and whether third-party modules are installed.

GCC compilers and related tools: GCC is all called the GNU Compiler Collection, is the GNU community launched a powerful, superior performance for programming development of the free compiler, is one of the GNU representative works, currently can compile the language includes: C, C + +, Objective-c, Fortran, Java and so on. You must make sure that your operating system has the GCC compiler installed.

In addition, you must also install the autoconf and Automake tools, which are used to automatically create fully functional makefile, most of which are generated makefile with this tool, and Nginx is no exception. Under the CentOS system, you can use the Yum command to install the GCC compiler and related tools:

Yum-y install gcc gcc-c++ autoconf automake

Module dependencies: Nginx modules require additional third-party library support, such as the Gzip module requires zlib library, rewrite module requires PCRE library, SSL function requires the OpenSSL library and so on. Similarly, if it is under the CentOS system, we can use the Yum command to install or download the source package to compile and install the libraries that these modules depend on:

Yum-y install zlib zlib-devel OpenSSL openssl–devel pcre pcre-devel

Nginx in the Linux environment can be compiled by the way to install the source, the simplest installation command is as follows:

Tar zxvf nginx-version number. tar.gz

CD nginx-version number

./configure

Make

Make install

In accordance with the above command, Nginx will be installed to the/usr/local/nginx directory by default.

You can use the/configure–help command to view Nginx's choice of compilation options.

Examples of compilation options are:

–prefix=<path> nginx installation path. If not specified, the default is/usr/local/nginx

–sbin-path=<path> nginx executable file installation path. Only specified when installed, default to <prefix>/sbin/nginx if not specified

–conf-path=<path> the path of the default nginx.conf under the given –c option. If not specified, the default is <prefix>/conf/nginx.conf

–pid-path=<path> the path of the default nginx.pid in case the PID directive is not specified in nginx.conf. If not specified, the default is <prerix>/logs/nginx.pid

Three Nginx command

Nginx commands help as follows

$/opt/ngx/sbin/nginx-h

Nginx version:nginx/0.8.45

Usage:nginx [-?HVVT] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:

-?,-H:this Help//

-v:show version and exit//display versions

-v:show version and configure options then exit//Display versions and configuration options

-t:test Configuration and exit//test config file, very important

-S signal:send signal to a master process:stop, quit, reopen, reload//Send signal

-P prefix:set Prefix path (default:/opt/nginx-0.8.45/)

-C filename:set configuration file (default:conf/nginx.conf)//Specify Profile

-G Directives:set Global directives out of configuration file

is the Nginx official website of the nginx signal interpretation of the document interception

Here are some common nginx commands

Nginx-c/path/to/nginx.conf//Start nginx with a configuration file in a specific directory:

Nginx-s Reload//Modify configuration after reload takes effect

Nginx-s reopen//reopen log file

Nginx-s Stop//Fast stop Nginx

Nginx-s quit//complete and orderly stop nginx

NGINX-T//Test the current configuration file is correct

NGINX-T-c/path/to/nginx.conf//test the specific Nginx configuration file is correct

Other orders to find out their own information, generally have introduced. Let's talk about this.

Four Nginx Log Cutting

Why cut logs? General Nginx installed after some people will open the log records, some people will turn off the log records, Open the log records of the people will generally be erected on the Nginx all the Web site logs exist in the same file (for example, I exist in the Access.log log file), so that the accumulation of all Web site access records will be the log file is larger, when the need to view the log file when a look is a large string, inconvenient to find. Now, if I split the daily log files and identify them with the appropriate dates, it's much easier to find them.

I recommend that you turn on logging and that there are many useful things in the log records. For example: Browser name, you can make adjustments to the layout of the site, IP address, if the site received an attack, you can find the IP address.

Linux we can simply put the log file mv Walk, but you will find that the new log file after the MV Walk is not regenerated, General Linux under the file handle, the file is opened under the circumstances of your MV go file, but the original operation of this file process or there is the inode of this file and other information, The original process or read and write the original file, so the simple MV is not effective.

So the recommended process is as follows

1. MV original file to the new file directory, this time Nginx also wrote this file (write to the new location file)

2. Call Nginx-s reopen to open the log file so that Nginx will write the new log information to the new file

This completes the log cutting work, while the cutting process without the loss of logs.

Five Nginx configuration file Overloading

Nginx work process, including master process, multiple worker processes, the worker process is responsible for specific HTTP and other related work, master process is mainly for control control. When you have modified the Nginx configuration file, you need to use the

NGINX-T Test the modified configuration file is correct, if not correctly continue to modify, until the test pass, in the test process, the nginx work has no impact (testing is only the work of master, the worker is responsible for the specific work, In the test, only master tests some configuration file structure definitions and so on. )

When the new profile test passes, we can

Nginx-s Reload command loads the modified configuration file, the following event occurs after the command is released

1. Nginx Master Process Check the correctness of the configuration file, if the error is returned error message, Nginx continue to work with the original configuration file (because the worker is not affected)

2. Nginx starts a new worker process with a new configuration file

3. Nginx assigns new request to new worker process

4. After all requests for the previous worker process have been returned, the associated worker process is closed

5. Repeat the process above and know that all the old worker processes have been shut down

The above process is to refer to the official Nginx related documents.

Reload effect and working process of Nginx reopen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.