官方源码包下载地址:
https://nginx.org/en/download.html
1.登录官网获取下载链接直接wget
[root@localhost ~]# wget https://nginx.org/download/nginx-1.16.0.tar.gz
2.解压文件
[root@localhost ~]# tar -xf nginx-1.16.0.tar.gz
3.检查当前环境是否符合编译要求,并生成makefile文件
[root@localhost ~]# cd nginx-1.16.0
[root@localhost nginx-1.16.0]# ./configure --prefix=/apps/nginx --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 --with-stream_realip_module
4.根据makefile文件内容生成指定的模块
[root@localhost nginx-1.16.0]# make
5.将生成的模块复制到相应的目录,如果目录不存在会创建目录 创建用户
[root@localhost nginx-1.16.0]# make install
[root@localhost nginx-1.16.0]# useradd nginx -s /sbin/nologin -u 2000
[root@localhost nginx-1.16.0]# chown nginx.nginx -R /apps/nginx/
[root@localhost nginx-1.16.0]# /apps/nginx/sbin/nginx -V //可查看版本
6.创建服务脚本
[root@localhost nginx-1.14.2]# vim /usr/lib/systemd/system/nginx.service
[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid #此项为进程的编号,可以在nginx的配置文件中查询的相应的位置
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf #编译安装时nginx二进制程序所在的位置以及配置文件所在的位置
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
7.将执行文件关联到sbin下
[root@localhost ~]# ln -s /apps/nginx/sbin/nginx /sbin/nginx
8.测试服务脚本是否能启动
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
#已经能够正常使用