(1) Go to the /usr/local directory

cd /usr/local
Copy the code

(2) Install nginx dependency packages

apt-get install build-essential 
Copy the code
apt-get install libtool 
Copy the code
sudo apt-get update
Copy the code

Check whether zlib is installed

dpkg -l | grep zlib 
Copy the code

Resolve dependency package OpenSSL installation

sudo apt-get install openssl libssl-dev 
yes 
Copy the code

Resolve dependency package PCRE installation

sudo apt-get install libpcre3 libpcre3-dev
yes
Copy the code

Resolve dependency package Zlib installation

sudo apt-get install zlib1g-dev 
Copy the code

Resolve dependency package SSL installation

apt-get install openssl
Copy the code

(3) the download nginx

Download nginx

Wget HTTP: / / http://nginx.org/download/nginx-1.13.1.tar.gzCopy the code

Unpack the nginx

The tar - XZVF nginx - 1.13.1. Tar. GzCopy the code

Rename the folder to nginx

The mv nginx - 1.13.1 nginxCopy the code

(4) install nginx

Configure nginx

cd /usr/local/nginx 
Copy the code
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf 
Copy the code

Compile nginx

sudo make 
Copy the code

Install nginx

sudo make install

Copy the code

(5) Check whether nginx is installed successfully

cd /usr/local/nginx/sbin 
Copy the code
./nginx -t
Copy the code

If (hint: nginx: [alert] could not open the error log file: open () “/ usr/local/nginx/logs/error log” failed (2: No such file or directory))

Is:

cd /usr/local/nginx/logs
Copy the code
sudo vim error.log 
Copy the code

Save and exit

Perform Step (5) again.

(6) Verify that the nginx startup user is the same as the nginx working user.

Change the user of nginx.config to the same as the startup user, for example, to root(user root;).

(7) to start the nginx

Method 1: Specify a path to the conf file as the Nginx configuration file (recommended)

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
Copy the code

Note: The configuration file is in usr->local->nginx->conf->nginx.conf

Method 2 Default configuration file nginx.conf

cd /usr/local/nginx/sbin 
Copy the code
./nginx 
Copy the code

Note: The configuration file is in nginx->nginx.conf