下载源码包至当前目录:wget https://nginx.org/download/nginx-1.28.0.tar.gz
yum -y install make zlib zlib-devel libtool gcc gcc-c++ openssl openssl-devel pcre-devel
tar -xzvf nginx-1.28.0.tar.gz -C /root
修改/root/nginx-1.28.0/src/core/nginx.h,将NGINX_VER值中的版本信息注释(若需要响应错误版本可修改NGINX_VERSION值)
修改/root/nginx-1.28.0/src/http/ngx_http_header_filter_module.c,修改Server:"nginx"(若只需要隐藏版本号则无需这一步)
修改/root/nginx-1.28.0/src/http/ngx_http_special_response.c,修改NGINX_VER值(若只需要隐藏版本号则无需这一步)
配置安装选项,prefix指定安装目录,user指定启动用户,group指定启动用户组, --with-http_addition_module输出过滤器,支持不完全缓冲,分部分响应请求 --with-http_dav_module启用支持(增加PUT、DELETE、MKCOL:创建集合,COPY和MOVE方法)。默认关闭,需要编译开启 --with-http_flv_module提供flv视频文件支持 --with-http_gzip_static_module压缩功能支持 --with-http_mp4_module提供mp4视频文件支持,提供伪流媒体服务端支持 --with-http_ssl_module安装ssl模块, --with-http_stub_status_module安装stub模块,获取Nginx的状态统计信息 --with-http_sub_module允许一些其他文本替换Nginx相应中的一些文本 --with-pcre正则表达式支持
在/root/nginx-1.28.0目录下执行:
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_mp4_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-pcre
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
nginx -v
useradd -M -s /sbin/nologin nginx
curl -o /tmp/install-nginx.sh https://mengruo.top/htmls/Linux/sh/install-nginx.sh
sh /tmp/install-nginx.sh
启动服务:nginx
检查配置文件的语法:nginx -t
重载配置:nginx -s reload
停止服务:nginx -s stop