准备
下载nginx源码包
这里我下载的是nginx-1.24.0.tar.gz
版本 下载完之后,我们使用mobaxterm
将nginx-1.24.0.tar.gz
上传到我们的Linux服务器
的/root/
目录下
[ root@nginx ~]
公共 视频 文档 音乐 anaconda-ks.cfg vmset-rhel9-mountYum.sh
模板 图片 下载 桌面 nginx-1.24.0.tar.gz
关闭firewalld和selinux
[ root@nginx ~]
inactive
[ root@nginx ~]
Disabled
安装依赖环境
[ root@nginx ~]
安装
解压
[ root@nginx ~]
[ root@nginx ~]
公共 视频 文档 音乐 anaconda-ks.cfg nginx-1.24.0.tar.gz
模板 图片 下载 桌面 nginx-1.24.0 vmset-rhel9-mountYum.sh
关闭nginx
的debug
功能
[ root@nginx ~]
执行./configure
进行环境检测
[ root@nginx ~]
[ root@nginx nginx-1.24.0]
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[ root@nginx nginx-1.24.0]
> --user = nginx \
> --group = nginx \
> --with-http_ssl_module \
> --with-http_v2_module \
> --with-http_realip_module \
> --with-http_stub_status_module \
> --with-http_gzip_static_module \
> --with-pcre \
> --with-stream \
> --with-stream_ssl_module
configure
用来进行环境检测
检测通过会生成Makefile
文件和objs目录
[ root@nginx nginx-1.24.0]
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
如果想重新检测
,可以使用make clean
,他就会删除Makefile
和objs
[ root@nginx nginx-1.24.0]
rm -rf Makefile objs
添加nginx系统用户
由于我们在./configure
的时候,指定了user运行用户
和group运行组
,所以我们要添加nginx用户
[ root@nginx ~]
使用make
编译
[ root@nginx nginx-1.24.0]
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[ root@nginx nginx-1.24.0]
使用make
执行编译
后,objs
目录里面就会出现编译后生成的文件
,这些文件
才是我们软件运行时真正需要的文件
编译的过程
:nginx
中的源文件
与系统中
的C语言的头文件
进行对接编译完成
会在objs目录
下生成nginx的启动脚本
和nginx所需要的模块
。其中启动脚本为nginx
,模块放在objs/src
目录下
当然,我们在make
编译时也可以使用-j
指定cpu的核心数
,提高编译速率
[ root@nginx nginx-1.24.0]
使用make install
安装
make install
本质:将objs目录
中的文件
复制到prefix
指定的目录中
[ root@nginx nginx-1.24.0]
进入到prefix
指定的目录中查看
[ root@nginx ~]
[ root@nginx nginx]
conf html logs sbin
启动nginx服务
[ root@nginx sbin]
[ root@nginx sbin]
avahi 771 0.0 0.1 15524 6280 ? Ss 00:43 0 :00 avahi-daemon: running [ nginx. local]
root 39425 0.0 0.0 9832 928 ? Ss 01:33 0 :00 nginx: master process ./nginx
nginx 39426 0.0 0.1 13720 4572 ? S 01:33 0 :00 nginx: worker process
root 39428 0.0 0.0 221812 2320 pts/0 S+ 01:33 0 :00 grep --color = auto nginx
关闭nginx
[ root@nginx sbin]
[ root@nginx sbin]
root 39437 0.0 0.0 221812 2316 pts/0 S+ 01:35 0 :00 grep --color = auto nginx
添加nginx环境变量
[ root@nginx ~]
if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi
export PATH = $PATH :/usr/local/nginx/sbin
[ root@nginx ~]
[ root@nginx ~]
/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/nginx/sbin
卸载nginx
[ root@nginx ~]
[ root@nginx ~]
[ root@nginx nginx-1.24.0]
rm -rf Makefile objs