1. gcc:nginx编译依赖gcc环境
安装命令:yum install gcc-c++
2.pcre:(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用 pcre来解析正则表达式.
安装命令:yum install -y pcre pcre-devel
3.zlib:该库提供了很多种压缩和解压缩的方式,nginx使用zlib对 http包的内容进行gzip。
安装命令:yum install -y zlib zlib-devel
4.openssl:一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http 协议,还支持https(即在ssl协议上传输 http).
安装命令:yum install -y openssl openssl-devel
5.下载nginx源码包(我把nginx安装在/usr/local下,所以cd /usr/local)
下载命令:wget http://nginx.org/download/nginx-1.20.2.tar.gz
可以到官网下载最新的nginx: download,我选的stable version
7.解压缩源码包并进入
1).解压缩:tar -zxvf nginx-1.20.2.tar.gz
2).进入解压缩后文件夹:cd nginx-1.20.2
8.编译,默认https没有打开,需要添加 --with-http_ssl_module
配置命令 ./configure --with-http_ssl_module
9.编译并安装 make && make install
10.启动nginx
1).进入安装目录 cd /usr/local/nginx/sbin/
2).启动 ./nginx
11.配置nginx命令
1).打开文件 vim /etc/profile
2).在最后一行添加
PATH=$PATH:/usr/local/nginx/sbin
export PATH
3)保存配置
执行 source /etc/profile
附nginx命令:
1.启动Nginx
nginx
2.快速停止和关闭Nginx
nginx -s stop
3.正常停止或关闭Nginx
nginx -s quit
4.配置文件修改重新加载
nginx -s reload
5.测试Nginx配置文件的正确性及配置文件的详细信息
nginx -t