Steps of installing nginx in linux Environment

Before starting, please confirm whether the gcc g + + development class library is installed. It is installed by default.

The following instructions can be used in the Ubuntu platform compilation environment

apt-get install build-essential
apt-get install libtool

centos platform compilation environment uses the following instructions

Install make:

yum -y install gcc automake autoconf libtool make

Install g + +:

yum install gcc gcc-c++

Let's officially begin:

1, Selected installation file directory

You can choose any directory. For this article, choose cd /usr/local/src

1 cd /usr/local/src

2, Install PCRE Library

   ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ Download the latest PCRE source code package and use the following command to download, compile and install the PCRE package: (this article refers to the download file version: pcre-8.37.tar.gz. This version is not found after verification. If you want to download the latest version, please open the above website. This article selects pcre-8.39.tar.gz)

cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz 
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
./configure
make
make install

3, Install zlib Library

   http://zlib.net/zlib-1.2.11.tar.gz Download the latest zlib source code package, and use the following command to download, compile and install the zlib package: (this article refers to the download file version: zlib-1.2.8.tar.gz) this version is not found after verification. If you want to download the latest version, please open the above website. This article selects zlib-1.2.11. Tar. GZ)

cd /usr/local/src
 
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install

4, Install openssl (some vps do not install SSL by default)

cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz

5, Installing nginx

There are generally two versions of Nginx, namely, stable version and development version. You can choose one of these two versions according to your purpose. The following are the detailed steps to install Nginx in / usr/local/nginx Directory:

cd /usr/local/src
wget http://nginx.org/download/nginx-1.1.10.tar.gz
tar -zxvf nginx-1.1.10.tar.gz
cd nginx-1.1.10
./configure
make
make install

Note: errors may appear here

  

Follow the method in step 4 or

ubuntu lower

apt-get install openssl
apt-get install libssl-dev

centos

yum -y install openssl openssl-devel

6, Start nginx

Because apeache may occupy port 80, we should try not to modify apeache port. We choose to modify nginx port.

linux modify path / usr / local / nginx / conf / nginx Conf, installation directory under Windows \ conf \ nginx conf.

Change the port to 8090 and localhost to your server ip address. (success is at hand!!)

  

Start nginx

netstat -ano|grep 80

If the execution result cannot be found, the previous step will be ignored (sudo must be used to start under ubuntu, otherwise it can only be run in the foreground)

sudo /usr/local/nginx/nginx

7, nginx restart, shutdown and startup

start-up

Startup code format: nginx installation directory address - c nginx configuration file address

For example:

[root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 

stop it

There are three ways to stop nginx:

  • Stop calmly

1. Check the process number

[root@LinuxServer ~]# ps -ef|grep nginx

 

2. Kill the process

[root@LinuxServer ~]# kill -QUIT 2072

 

  • Quick stop

1. View process number

[root@LinuxServer ~]# ps -ef|grep nginx

 

2. Kill process

[root@LinuxServer ~]# kill -TERM 2132
or [root@LinuxServer ~]# kill -INT 2132

 

  • Forced stop

 

[root@LinuxServer ~]# pkill -9 nginx

 

 

restart

1. Verify that the nginx configuration file is correct

Method 1: enter the nginx installation directory sbin and enter the command/ nginx -t

See the following display nginx conf syntax is ok

nginx.conf test is successful

The configuration file is correct!

 

Method 2: add - t before the start command - c

2. Restart Nginx service

Method 1: enter nginx executable directory sbin and enter the command/ nginx -s reload +

Method 2: find the current nginx process number, and then enter the command: kill -HUP process number to restart the nginx service

 

8, Final result:

  

 

9, Project file storage path

Put it under this file and create a folder.

 

 

Tags: Nginx

Posted by chedong on Wed, 18 May 2022 17:03:53 +0300