1 下载Nginx
官网地址:
官网 http://nginx.org/
下载稳定版本和之前的版本都可以,这里我下载的是
nginx-1.16.1
CSDN地址:
2 上传文件到服务器
可以用ftp工具将文件上传到目录 /opt/software/
目录不存在需自己创建
[root@localhost software]# ll
总用量 1012
-rw-r--r--. 1 root root 1032630 1月 27 13:18 nginx-1.16.1.tar.gz
[root@localhost software]#
3 安装依赖环境
3.1 安装gcc环境
[root@localhost software]# yum install gcc-c++
3.2 安装PCRE库,用于解析正则表达式
[root@localhost software]# yum install -y pcre pcre-devel
3.3 zlib压缩和解压缩依赖
[root@localhost software]# yum install -y zlib zlib-devel
3.4 SSL 安全的加密的套接字协议层,用于HTTP安全传输,也就是https
[root@localhost software]# yum install -y openssl openssl-devel
4 编译源码
4.1 解压文件
[root@localhost software]# tar -zxvf nginx-1.16.1.tar.gz
4.2 创建nginx临时目录
[root@localhost software]# mkdir /var/temp/nginx -p
[root@localhost software]# /opt/module/software/nginx-1.16.1
4.3 创建makefile文件
4.3.1 使用默认配置
[root@localhost nginx-1.16.1]# ./configure
4.3.2 自定义配置
[root@localhost nginx-1.16.1]#
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
./configure \
命令 | 解释 |
---|---|
–prefix | 指定nginx安装目录 |
–pid-path | 指向nginx的pid |
–lock-path | 锁定安装文件,防止被恶意篡改或误操作 |
–error-log | 错误日志 |
–http-log-path | http日志 |
–with-http_gzip_static_module | 启用gzip模块,在线实时压缩输出数据流 |
–http-client-body-temp-path | 设定客户端请求的临时目录 |
–http-proxy-temp-path | 设定http代理临时目录 |
–http-fastcgi-temp-path | 设定fastcgi临时目录 |
–http-uwsgi-temp-path | 设定uwsgi临时目录 |
–http-scgi-temp-path | 设定scgi临时目录 |
4.4 make 编译
[root@localhost nginx-1.16.1]# make
4.5 安装
[root@localhost nginx-1.16.1]# make install
5 管理服务
5.1 启动
[root@localhost nginx-1.16.1]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx
5.2 停止
[root@localhost sbin]# ./nginx -s stop
5.3 重新加载
[root@localhost sbin]# ./nginx -s reload