1. 下载nginx
http://nginx.org/en/download.html
2. 解压‘nginx-1.16.1.tar.gz’到指定目录
tar -xvf nginx-1.16.1.tar.gz -C /usr/local/nginx
3. 安装环境准备
#安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境
yum -y install gcc-c++
#PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库,nginx 的 http 模块使用 pcre 来解析正则表达式
#pcre-devel 是使用 pcre 开发的一个二次开发库
yum -y install pcre pcre-devel
#zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip
yum -y install zlib zlib-devel
#OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http)
yum -y install openssl openssl-devel
#或者直接
yum -y install gcc pcre-devel zlib-devel openssl openssl-deve
bash ./configure
4.安装
-
简单安装:
进去nginx路径,全部采用默认安装- ./configure
- make && make install
执行完成之后 nginx 运行文件 就会被安装在 /usr/local/nginx 下。
-
自定义安装
- ./configure --prefix=/usr/local/myWorkSpace/nginx1.16 --with-http_stub_status_module --with-http_ssl_module --with-debug
2)make && make install
- ./configure --prefix=/usr/local/myWorkSpace/nginx1.16 --with-http_stub_status_module --with-http_ssl_module --with-debug
-
检测是否安装成功
[root@test12 nginx]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
5.启动nginx
cd /usr/local/myWorkSpace/nginx1.16/sbin
./nginx
启动 nginx:./nginx -s start
优雅停止 nginx:./nginx -s quit
快速停止 nginx:./nginx -s stop
重启nginx:./nginx -s reload
或者一次简洁安装
安装nginx服务
yum -y install gcc pcre-devel zlib-devel openssl openssl-deve
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure
make && make install