1. 下载源码包
[root@qls ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz[root@qls ~]# ll
total 1016
-rw-r--r-- 1 root root 1039530 Apr 21 22:33 nginx-1.18.0.tar.gz
2. 解压软件包
[root@qls ~]# tar xf nginx-1.18.0.tar.gz [root@qls ~]# ll
total 1016
drwxr-xr-x 8 user05 1001 158 Apr 21 22:09 nginx-1.18.0
-rw-r--r-- 1 root root 1039530 Apr 21 22:33 nginx-1.18.0.tar.gz
3. 进入这个目录,进行预编译操作 编译设置
[root@qls nginx-1.18.0]# ./configure --prefix=/opt/nginx-1.18.0 --with-http_ssl_module
checking for OS
+ Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found #报错 缺少编译软件 gcc#安装依赖[root@qls nginx-1.18.0]# yum install -y gcc#再次执行报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
#解决:[root@qls nginx-1.18.0]# yum install -y pcre pcre-devel #再次执行报错
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
#解决:[root@qls nginx-1.18.0]# yum install -y openssl openssl-devel
4. 编译
[root@qls nginx-1.18.0]# make
5. 将编译的结果拷贝到指定的位置
[root@qls nginx-1.18.0]# make install[root@qls nginx-1.18.0]# ll /opt/
drwxr-xr-x 6 root root 54 Jul 31 16:54 nginx-1.18.0
6. 做个软链接
[root@qls ~]# ln -s /opt/nginx-1.18.0/ /opt/nginx
7. 启动
[root@qls ~]# /opt/nginx/sbin/nginx