Linux test Environment Deployment Nginx (v)

Source: Internet
Author: User

Installation Configuration Nginx

    1. Install the build environment: yum-y Install pcre-devel OpenSSL openssl-devel
    2. After copying the Nginx compressed file to the target directory, unzip the TAR-ZXVF nginx1.4.4.tar.gz
    3. Set compilation parameters:./configure--prefix=/usr/local/nginx--with-http_stub_status_module (run under/usr/local/nginx directory)
    4. Compiling: Make
    5. Install: Make install
    6. Start cd/usr/local/nginx/sbin/

./nginx

CentOS installation of Nginx (yum installation)

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 compiler and related tools: gcc is all called the GNU Compiler collection,  is the GNU community launched a powerful, The high performance of the free compiler for programming development, 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 install the autoconf and Automake tools , which are used to automatically create fully functional makefile, and most of the current packages are generated makefile with this tool, Nginx is no exception. Under the CentOS system, you can install the GCC compiler and related tools using the Yum command:  
yum-y install gcc gcc-c++ autoconfautomake  
Module dependencies: Some of the Nginx modules require support from other third-party libraries, such as the gzip module requires the zlib library, the rewrite module requires a pcre library, and the SSL function requires the OpenSSL library . Similarly, if it is under the CentOS system, we can use the Yum command to install or download the source package compiled to install libraries dependent on these modules:  
yum-y install zlib zlib-devel Opensslopenssl--devel pcre pcre-devel  

Nginx can be installed in Linux environment by compiling the source . The simplest installation command is as follows:

TARZXVF 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

Wait a minute

Nginx start, stop, smooth reboot

start Nginx
To start Nginx, you can execute the following command. Assuming Nginx is installed in the/usr/locaunginx/directory, the command to start Nginx is:
/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf

The parameter "-C" specifies the path to the configuration file, and if you do not add the "-C" parameter, Nginx will load the nginx.conf file in the Conf subdirectory of its installation directory by default.

Nginx the Stop
Nginx Stop method has many kinds, generally by sending the system signal to the NGINX main process way to stop nginx.
We can use the PS command to find the main process number of Nginx:
PS –ef | grep nginx

As you can see, the note information for the 1 Nginx processes is "master process", which indicates that it is the main process, and the other 1 process notes are "worker process", which indicates that they are child processes. 32244 the main process number.
If the path of the PID file is specified in the nginx.conf configuration file (for example:/usr/local/webserver/nginx/logs/nginx.pid;), the file contains the Nginx current main process number. If you do not specify a path to the PID file, the Nginx.pid file is stored by default in the logs directory of the Nginx installation directory. Therefore, we can also directly through the following command to complete, save to find the Nginx main process number of the steps:
Kill- signal type '/usr/local/webserver/nginx/logs/nginx.pid '

(1) calmly stop nginx.
kill-quit Nginx The main process number or kill-quit '/usr/local/webserver/nginx/logs/nginx.pid '

(2) Quick Stop Nginx
kill-term Nginx The main process number or kill-term '/usr/local/webserver/nginx/logs/nginx.pid '

Kill-int Nginx The main process number or kill-int '/usr/local/webserver/nginx/logs/nginx.pid '

(3) Force stop all Nginx processes

Pkill –9nginx

Nginx The smooth restart

If you change the Nginx configuration file (Nginx conf), you want to restart the Nginx, you can also send the system signal to the NGINX main process of the way to do. However, before restarting, verify that the syntax of the Nginx configuration file (nginx.conf) is correct, otherwise nginx will not load the new configuration file. Use the following command to determine if the Nginx configuration file is correct:
/usr/local/webserver/nginx/sbin/nginx –t-c
/usr/local/webserver/nginx/conf/nginx.conf

If the configuration file is incorrect, the screen will prompt for the first few lines of the configuration file:
[emerg]:unknown directive "ABC" in/usr/local/webserver/nginx/conf/nginx.conf:55

Configuration file/usr/local/webserver/nginx/conf/nginx.conf test Failed

If the configuration file is correct, the screen will prompt for two lines of information:
The configuration file/usr/local/webserver/nginx/conf/nginx.conf syntaxis OK
Configuration file/usr/local/webserver/nginx/conf/nginx.conf Test Issuccessful

This time, you can smoothly restart Nginx.
kill-hup Nginx Main process Number
Kill
a hup '/usr/local/webserver/nginx/logs/nginx.pid '

When Nginx receives the HUP signal, it attempts to parse the configuration file and, if successful, applies a new configuration file (for example, reopening the log file or listening socket). After that, Nginx runs the new worker process and gracefully shuts down the old worker process. Notifies the worker process to turn off the listener socket, but continues to service the currently connected customer. After all client services are completed, the old worker process is closed. If the new profile application fails, Nginx will continue to work with the old configuration.

Nginx the following types of signals are supported:
· Term,int fast closing;
· Quit calmly closed;
· Hup Smooth Restart, reload the configuration file;
· USR1 re-open the log file, the use of large in the cutting log;
· USR2 smooth upgrade executable program;
· Winch gracefully shuts down the worker process.

Nginx the smooth upgrade
When you need to upgrade, add, and delete the server module in the running Nginx, you can replace the old version of the executable program with the new version and the recompiled Nginx executables without interrupting the service. The steps are as follows:

(1) Replace the old executable program with the new executable program, the new version can be compiled and installed to the old version of the Nginx installation path for the installation of Nginx. Before you replace it, you might want to back up the old executable file.

(2) Send the following command:
Kill –USR2 old Nginx Master process number

(3) The previous version of Nginx's main process will rename its. pid file to. Oldbin (for example:/usr/local/webserver/nginx/logs/nginx.pid.oldbin), and then execute the new version of the Nginx executable program. Start the new master process and the new worker process in turn.

(4) At this time, the new and old version of Nginx instance will run concurrently, processing the input request together. to gradually stop an old nginx instance, you must send a winch signal to the old master process , and then its worker process will begin gracefully shutting down:
Kill-winch old Nginx Master process number

(5) After a period of time, the old worker process processes all connected requests and exits, and only the new worker process processes the input requests:

(6) At this time, we can decide whether to use the new version or revert to the old version:
Kill –hup The Old main process number: Nginx will start its work process without overloading the configuration file;
Kill
–quit New main process number: gracefully closes its work process (workerprocess);
Kill
–term New main process number: forced exit;
Kill
The new main process number or the old main process number: If for some reason the new worker process cannot exit, send a kill signal to it.
After the new main process exits, the old master process removes the. Oldbin prefix, reverting to its. pid file, so that everything is restored before the upgrade. If you try to upgrade successfully and you also want to keep the new server, you can send a quit signal to the old master process, leaving it to exit and leave the new server running:

Linux test Environment Deployment Nginx (v)

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.