Home  >  Article  >  Operation and Maintenance  >  Linux installation nginx server example code analysis

Linux installation nginx server example code analysis

WBOY
WBOYforward
2023-05-12 18:55:15665browse

nginx relies on some software libraries. Before installation, please make sure that the system has software such as gcc, ssl, pcre, and gzip installed. You can use the rpm -q command to check whether the software is installed.

[root@redhat1 ~]# rpm -q gcc
gcc-4.1.2-44.el5

The dependent library information is as follows:

(1). The gzip module requires the zlib library
(2). The rewrite module requires the pcre library
(3). The ssl function requires the openssl library

If you install pcre , download pcre to the destination directory, the version selected here is pcre-8.38, after downloading, perform the following operations

tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make
make install

Install nginx, execute the following command

By default In this case, the compiled and installed nginx already contains most of the available modules. You can set the usage of each module through the "./configure --help" option. For example, for the unnecessary http_ssi module, you can use "--without-http_ssi_module" " parameter to turn off this module; if you need the "http_perl" module, you can install this module through the "--with-http_perl_module" parameter. Perform the following steps to install.

tar -zxvf nginx-1.11.1.tar.gz
cd nginx-1.11.1
./configure --with-pcre=../pcre-8.38 --prefix=/usr/local/nginx
make
make install

To check whether the installation is successful, execute the following command

[root@redhat1 sbin]# cd /usr/local/nginx/sbin
[root@redhat1 sbin]# ./nginx -t

The following information appears to prove that the installation is successful

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

Start nginx

[root@redhat1 sbin] # ./nginx

View port

[root@redhat1 sbin]# netstat -ntlp

The results are as follows:

proto recv-q send-q local address foreign address state pid/program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* listen 2993/hpiod
tcp 0 0 0.0.0.0 :834 0.0.0.0:* listen 2772/rpc.statd
tcp 0 0 0.0.0.0:11111 0.0.0.0:* listen 3391/ricci
tcp 0 0 0.0.0.0:111 0.0.0.0:* listen 2733/portmap
tcp 0 0 0.0.0.0:80 0.0.0.0:* listen 3852/nginx
tcp 0 0 0.0.0.0:16851 0.0.0 .0:* listen 3290/modclusterd
tcp 0 0 127.0 .0.1: 631 0.0.0.0:* Listen 3024/CUPSD
TCP 0 0 127.0.1:25 0.0.0.0:* Listen 3057/Sendmail: Acce
TCP 0 0 127.0.0.1:2207 0.0.0.0: * listen 2998/python
tcp 0 0 :::22 :::* listen 3013/sshd

You can also enter in the browser: http://localhost to verify whether the startup is successful. .

Stop nginx

The stop operation is performed by sending a signal to the nginx process

Step 1: Query the nginx master Process number:

ps -ef | grep nginx

Look for the master process in the process list. Its number is the main process number.

Step 2: Send signal

Stop nginx gracefully: kill -quit main process number
Quickly stop nginx: kill -term main Process number
Force to stop nginx: pkill -9 nginx

Restart nginx: smooth restart

If you change the configuration, you must restart nginx. You must first close nginx and then Open? No, you can send a signal to nginx to restart smoothly.
Smooth restart command:

kill -hup live name or process ID file path or /usr/local/nginx/sbin/nginx -s reload

Note, after modifying the configuration file, it is best to check whether the modified configuration file is correct to avoid nginx errors after restarting, which will affect the stable operation of the server. The command to determine whether the nginx configuration is correct is as follows:


nginx -t -c /usr/local/nginx/conf/nginx.conf or /usr/local/nginx/sbin /nginx -t

The above is the detailed content of Linux installation nginx server example code analysis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete