How to install Nginx under Centos

王林
Release: 2023-05-18 17:13:27
forward
1844 people have browsed it

nginx("engine x") is a lightweight http and reverse proxy server. Compared with apache, lighttpd, etc., it has the advantages of less memory, strong concurrency, and high stability. Its most common use is to provide reverse proxy services.

Under Linux, we need to download the nginx source code package and compile it manually instead of using package management tools such as yum and aptitude to install it. Because we need to configure nginx during compilation, we have to compile it manually, which also relies on some tools and library files.

First of all, you need to install the c language compilation environment, because nginx is written in c language. Usually most Linux will install gcc by default. If not, you can install it as follows.

Install make:

yum -y install gcc automake autoconf libtool make

Install g:

yum install gcc gcc-c

pcre library:

nginx requires pcre (perl compatible regular expression), because nginx’s rewrite module and The http core module will use pcre regular expression syntax. The download address is, we can also install it through yum.

yum install pcre pcre-devel

How to install Nginx under Centos

The above is the installed prompt.

zlib library:

The zlib library provides a compression algorithm, and the gzip algorithm is used in many places in nginx. Its download address is, and it can also be installed through yum.

yum install zlib zlib-devel

How to install Nginx under Centos

The above is the case where the package is not installed or is not the latest package.

openssl:

If the server provides a secure page in nginx, you need to use the openssl library. Its download address is, and it can also be installed through yum.

yum install openssl openssl-devel

Download nginx:

nginx source code package can be downloaded from the official website, the latest stable version is currently As of 1.10.1, there is also a development version available. The relevant commands are as follows:

wget
tar zxf nginx-1.10.1.tar.gz
cd nginx-1.10.1/

Install nginx:

Configuration is required before installation, which is also a common step for installing software under Linux. You can directly use the configure script for initial installation. If necessary, you can set switch options to enable the required functional modules, which will not be expanded here. The relevant commands are as follows:

./configure
make
make install

Run nginx:

nginx will be installed by default In the /usr/local/nginx directory, we cd to the /usr/local/nginx/sbin/ directory, and there is an nginx binary executable file. You can start nginx by running it directly. After the operation is successful, open the browser to access the IP of this machine. If the following screen appears, it is successful.

How to install Nginx under Centos

nginx related commands:

nginx -h ------------- ------------> Help command

nginx -s stop ------------------------ -> Immediately stop the daemon process (term signal)

nginx -s quit -------------------------> Mild Stop the daemon process (quit signal)

nginx -s reopen -------------------------> Reopen the log file

nginx -s reload -------------------------> Reload the configuration file

nginx -t - --------------------------> Test whether the configuration file is legal

killall nginx ----------- --------------> Forcefully terminate the nginx process

Since any nginx command checks whether the configuration file is legal, if the configuration file is illegal, the command will not be executed, killall The command can avoid being unable to stop the nginx service.

nginx configuration file has its own unique syntax, which will not be expanded upon here.

The above is the detailed content of How to install Nginx under Centos. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template