nginx安装记录
1 ,nginx安装环境
(1),linux 内核2.6及以上版本
只有2.6之后才支持epool ,在此之前使用select或pool多路复用的IO模型,无法解决高并发压力的问题。通过命令uname -a 即可查看。
uname -a
(2),gcc
nginx是C语言开发,安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:
yum install gcc-c++
(3),PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
(4),zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
(5),openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
注:也可直接使用yum命令统一安装:
yum -y install make zlib zlib-devel gcc-c++ openssl openssl-devel pcre pcre-devel
2,下载,安装
nginx下载地址:
http://nginx.org/en/download.html
下载nginx最新稳定版本:
wget http://nginx.org/download/nginx-1.16.1.tar.gz
解压:
tar -zxvf nginx-1.16.1.tar.gz
进入解压目录:
cd nginx-1.16.1
基于参数构建:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-debug
编译安装
make && make install
执行完成之后 nginx 运行文件 就会被安装在 /usr/local/nginx 下。
进入安装目录并启动nginx:
进入安装目录
cd /usr/local/nginx
启动nginx
./sbin/nginx
在浏览器访问虚拟机IP出现下图:
一些常用命令:
默认方式启动:
./sbin/nginx
指定配置文件启动
./sbin/nginx -c /usr/local/nginx-1.16.1/conf/nginx.conf
快速停止
./sbin/nginx -s stop
优雅停止
./sbin/nginx -s quit
热装载配置文件
./sbin/nginx -s reload
重新打开日志文件
./sbin/nginx -s reopen