Install nginx on CentOS

1. nginx installation

Download nginx:

Official website:

https://nginx.org/en/download.html

The version I am using is version 1.8.0.


1.1. Required installation environment

1. You need to install the gcc environment.

yum install gcc-c++

2. Third-party development kits.

n PCRE

PCRE (Perl Compatible Regular Expressions) is a Perl library that includes a perl-compatible regular expression library. The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on linux.

yum install -y pcre pcre-devel

Note: pcre-devel is a secondary development library developed using pcre. nginx also requires this library.

n zlib

The zlib library provides many ways to compress and decompress. nginx uses zlib to gzip the content of the http package, so the zlib library needs to be installed on linux.

yum install -y zlib zlib-devel

n openssl

OpenSSL is a powerful secure socket layer cryptographic library, including major cryptographic algorithms, commonly used key and certificate encapsulation management functions and SSL protocols, and provides a wealth of applications for testing or other purposes.

Nginx supports not only the http protocol, but also https (that is, transmitting http over the ssl protocol), so you need to install the openssl library in linux.

yum install -y openssl openssl-devel

1.2. Installation steps

The first step: upload the source package of nginx to the linux system

Step 2: Unzip

[root@localhost ~]# tar zxf nginx-1.8.0.tar.gz

Step 3: Use the configure command to create a makeFile file.

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

Note: Before starting nginx, the temporary file directory is specified as /var/temp/nginx , and the temp and nginx directories need to be created under /var

[root@localhost sbin]# mkdir /var/temp/nginx/client -p

Step 4: make

Step 5: make install

clip_image004

1.3. Start nginx

Enter the sbin directory

[root@localhost sbin]# ./nginx
clip_image006

Turn off nginx:

[root@localhost sbin]# ./nginx -s stop

Recommended Use:

[root@localhost sbin]# ./nginx -s quit

Restart nginx:

1. Turn it off first and then start it.

2. Refresh the configuration file:

[root@localhost sbin]# ./nginx -s reload

1.4. Access nginx

clip_image008

The default is port 80.

Note: Whether to turn off the firewall.

Guess you like

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