Install nginx from source code to the specified directory

The first is a summary of all the steps

yum install libaio ncurses gcc gcc-c++ cmake ncurses-devel wget
yum install pcre-devel zlib-devel
wget http://nginx.org/download/nginx-1.16.1.tar.gz # 下载源码包
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --prefix=/opt/nginx1.16 # 这里指定安装目录
make && make install
useradd www -s /bin/false
vi /opt/nginx1.16/conf/nginx.conf # 修改配置文件
# 第一行去掉前面井号并改为 user  www;
/opt/nginx1.16/sbin/nginx #启动nginx
#以下为可选
/opt/nginx1.16/sbin/nginx -s stop  #停止
/opt/nginx1.16/sbin/nginx -s reload  #重新载入配置

1. Install the compiler and dependencies

yum install libaio ncurses gcc gcc-c++ cmake ncurses-devel wget
yum install pcre-devel zlib-devel

These dependencies are needed to compile nginx, otherwise the compilation cannot be completed

2. Download the source code package and unzip it

wget http://nginx.org/download/nginx-1.16.1.tar.gz # 下载源码包
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1

3. Compile and install

./configure --prefix=/opt/nginx1.16 # 这里指定安装目录
make && make install

You can make the installation directory before compiling, so that all data, configuration, and programs will be placed in this directory

You can also not specify, as shown below

./configure
make && make install

This will install to the default location

4. Add users used by nginx

useradd www -s /bin/false
vi /opt/nginx1.16/conf/nginx.conf # 修改配置文件
# 第一行去掉前面井号并改为 user  www;

By default, nginx does not use the root user to run the scripts of the website, but uses nobody, because once the malicious script is executed, the consequences are very serious

But nobidy's permissions are very small. We usually create a new nginx user or www user as a user for nginx

5. Start and restart

/opt/nginx1.16/sbin/nginx #启动nginx
/opt/nginx1.16/sbin/nginx -s stop  #停止
/opt/nginx1.16/sbin/nginx -s reload  #重新载入配置

Insert picture description here

Guess you like

Origin blog.csdn.net/zoollcar/article/details/104670389