Detailed explanation of manual compilation and installation of Nginx

1. Why should you compile Nginx manually?

In addition to compiling Nginx installation, we can also install it directly using the tools that come with the operating system, such as yum and apt-get.

However, there is a problem with directly installing the Nginx binary file: the Nginx binary file will compile the module directly. Not every Nginx official module will be enabled by default. If you want to add a third-party Nginx module, you must compile Nginx to integrate the powerful third-party ecosystem. The functionality in the circle is added to Nginx.

2. Download Nginx

1. Official website

http://nginx.org/

Find the download in the lower right corner:
Insert image description here
Insert image description here
we copy the link address to the linux server.
Insert image description here

2. Download to linux server

# 下载
wget http://nginx.org/download/nginx-1.24.0.tar.gz
# 解压
tar -zxvf nginx-1.24.0.tar.gz
# 进入到源码目录
cd nginx-1.24.0/

3. Source code directory analysis

Insert image description here

  • auto directory: mainly contains core functions for compilation, lib libraries and core functions of auxiliary config configuration files.
  • CHANGES file: contains features and bug-fixes provided in each version of nginx.
  • CHANGES.ru file: Russian version of the change file.
  • conf directory: This directory contains sample configuration files.
  • configure script: This script is used to generate intermediate files and perform a necessary action before compilation.
  • contrib directory: Provides the vim tool. Use vim to highlight the conf configuration file (manual copy required: cp -r contrib/vim/* ~/.vim)
  • html directory: Two html files are provided, one is the homepage and the other is the 50x error.
  • man directory: help files.
  • src directory: source code.

4. Compile and install

# 查看configure 支持的参数,其中包含指定某些路径、开启某些模块、编译中特殊参数
#./configure --help | more

# 安装nginx必备依赖库
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
# 进行编译,指定安装目录,没什么报错就是编译成功
./configure --prefix=/nginx

Insert image description here
After the configure command is executed, some intermediate files will be generated and stored in the objs directory:
Insert image description here
among them, the ngx_modules.c file determines which modules will be compiled into nginx when we perform compilation.

# 在nginx根目录进行编译(configure所在的目录)
make

At this time, a large number of intermediate files are generated, as well as the executed nginx binary file (in the objs directory):
Insert image description here

# 安装(configure所在的目录)
make install

5. Installation directory

Insert image description here

  • The conf directory contains configuration files
  • The sbin directory contains binary executable files
  • The logs directory contains log files
  • html contains html files

3. Start

1. Start

# 进入到sbin目录
cd /nginx/sbin
# 启动
./nginx

2. Access port 80

Open the default index page!
Insert image description here

Guess you like

Origin blog.csdn.net/A_art_xiang/article/details/133012260