1、下载官网源码包,或者离线直接访问地址下载:
[root@~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
2、安装必要的环境(先检查是否包含,若缺失先本地下载对应rpm包后上传安装):
gcc gcc-c++ autoconf automake make
zlib zlib-devel openssl openssl-devel pcre pcre-devel
3、解压源码包并指定安装包存放路径,或者默认解压到当前目录:
[root@ ~]# tar xvf nginx-1.18.0.tar.gz -C /tmp/
[root@ ~]# tar xvf nginx-1.18.0.tar.gz
4、切换到安装包存放路径下(未指定路径默认当前目录):
[root@ ~]# cd /tmp/nginx-1.18.0
[root@ nginx-1.18.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
此时还没有Makefile文件
5、执行 ./configure并指定一些安装选项:
[root@ nginx-1.18.0]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.18
#指定了启动用户和组,安装路径等,若nginx用户不存在,需要创建用户 useradd nginx
这一步会检查安装环境是否完整,并产生Makefile文件,提供给后续的编译及安装依据
[root@ nginx-1.18.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
6、执行编译和安装:
[root@ nginx-1.18.0]# make && make install
然后去 /usr/local/nginx-1.18/下面去查看安装完成的nginx
7、如何使用nginx文件名去直接启动nginx,而不用绝对路径,修改 /etc/profile文件,来配置变量名
1>在最后添加上以下内容,具体nginx安装路径以实际为主,保存退出:
PATH=/usr/local/nginx-1.18/sbin:$PATH
export PATH
2>执行一下:source /etc/profile # 重启配置文件
启动方式:直接输入nginx回车即可;
查询状态:
ps -elf |grep nginx
关闭方式(杀掉进程):
pkill -9 nginx
当然也可以将nginx添加到进程管理或者service中,具体添加方式这里就不做详述了
注:编译安装同样适用于X86、及其他架构的机器