Install Nginx in Linux environment

The purpose of this article is to introduce the steps of installing Nginx under Linux (Centos).

1. First download the corresponding version you need in http://nginx.org/download/

2. Put the downloaded version of nginx into: /usr/local/nginx and decompress it

      Directive tar -zxvf nginx version name

3. Rename mv nginx version name New name (nginx)   ---- This step can be skipped, and the new name is named nginx here

4. Then enter the nginx directory and execute ./configure

Error reported during execution: Error message: ./configure: error: the HTTP rewrite module requires the PCRE library.

Solution: Install pcre-devel and openssl-devel to solve the problem Execute: yum -y install pcre-devel openssl openssl-devel

Then execute: ./configure

5.make 
6.sudo make install 

7. Check whether the installation is successful Enter /usr/local/nginx/sbin, execute ./nginx -t, the result is: xxxx is ok, xxxx is successful The installation is successful


8. nginx startup 

   执行: /usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/nginx.conf

   Use ps -ef | grep nginx to find the main process number of nginx. The execution result is as follows:


Among them, "master process" indicates that he is the main process, and the other "worker process" indicates that they are child processes. 9512 is the main process number

8. stop nginx

 (1) kill - QUIT Nginx main process number to stop slowly

 (2) kill - INT Nginx main process number Quick stop

 (3)kill -9 ngnix Force stops all Nginx processes

9. Nginx graceful restart

If you change the configuration file (nginx.conf) and want to restart Nginx, you need to confirm that the syntax of the Nginx configuration file is correct before restarting, otherwise Nginx will not load the new configuration file. Use the following command to determine whether the Nginx configuration file is correct

/usr/local/webserver/nginx/sbin/nginx -t -c

/usr/local/webserver/nginx/conf/nginx.conf

If the configuration is not correct, the screen will prompt which line of the configuration file is wrong.

Once configured correctly, it can be restarted:

kill - HUP Nginx main process number The HUP signal is to let the system try to parse the configuration file. If the parsing is successful, the new configuration file will be used. No will work with the old configuration.




 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324733436&siteId=291194637