1、下载

http://nginx.org/en/download.html
image.png

2、解压

  1. [root@localhost local]# tar -zxvf nginx-1.20.2.tar.gz

3、配置基本信息

  1. #配置configure --prefix 代表安装的路径,--with-http_ssl_module 安装ssl,--with-http_stub_status_module查看nginx的客户端状态
  2. [root@localhost nginx-1.20.2]# ./configure --prefix=/usr/local/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module

image.png

提示错误:[以上操作提示错误信息]

1、 安装 c++的环境

  1. 报错信息:
  2. checking for OS
  3. + Linux 3.10.0-862.el7.x86_64 x86_64
  4. checking for C compiler ... not found
  5. ./configure: error: C compiler cc is not found
  6. 解决:
  7. [root@localhost nginx-1.20.2]# yum install gcc-c++
  8. 再次执行 ./configure --prefix=/usr/local/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
  9. 可以看到我们的目录下,多了一个Makefile文件

2、安装 openssl

  1. 报错信息:
  2. ./configure: error: the HTTP rewrite module requires the PCRE library.
  3. You can either disable the module by using --without-http_rewrite_module
  4. option, or install the PCRE library into the system, or build the PCRE library
  5. statically from the source with nginx by using --with-pcre=<path> option.
  6. 解决:
  7. [root@localhost nginx-1.20.2]# yum -y install openssl openssl-devel

4、进行编译安装

  1. [root@localhost nginx-1.20.2]# make && make install

5、启动

  1. [root@localhost nginx-1.20.2]# ls
  2. auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README sbin src
  3. [root@localhost nginx-1.20.2]# cd sbin/
  4. [root@localhost sbin]# ls
  5. nginx
  6. [root@localhost sbin]# ./nginx

image.png

提示报错信息:

  1. nginx: [alert] could not open error log file: open() "/usr/local/nginx-1.20.2/logs/error.log" failed (2: No such file or directory)
  2. 2022/02/15 15:05:06 [emerg] 18233#0: open() "/usr/local/nginx-1.20.2/logs/access.log" failed (2: No such file or directory)
  3. 解决方式: 建个logs 文件夹
  4. [root@localhost nginx-1.20.2]# mkdir logs