1、安装前准备工作
[root@www ~]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel gd-devel
[root@www ~]# rpm -q pcre-devel zlib-devel gcc gcc-c++ make
#安装一些其它依赖包
[root@www ~]# yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel gd-devel
2、下载源码包文件地址:http://nginx.org/en/download.html
3、进入源码包文件夹
[root@www ~]# tar -zxvf nginx-1.18.0.tar.gz
[root@www ~]# cd nginx-1.18.0
4、进行编译安装(为了安全起见,可以先创建一个www用户和用户组)
#创建用户、组
[root@www ~]# groupadd www
[root@www ~]# useradd www -M -s /sbin/nologin -g www
[root@www ~]#./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-pcre \
--with-http_v2_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_image_filter_module \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_addition_module \
--with-http_realip_module \
--with-http_mp4_module \
--with-cc-opt=-Wno-error \
--with-http_dav_module \
5、进行 make 编译
[root@www ~]# make
6、进行 make install
7、检查一下配置
#测试一下配置文件
[root@www ~]# /usr/local/nginx/sbin/nginx -t
8、设置拥有者和操作权限如下:
[root@www ~]# chown -R www:www /usr/local/nginx/
[root@www ~]# chmod -R 755 /usr/local/nginx/
9、启动nginx 、关闭、重启
#启动
[root@www ~]# cd /usr/local/nginx/sbin/
[root@www ~]# ./nginx
#关闭 好几种方式,最简单粗暴 ./nginx -s stop 或者 pkill -9 nginx
[root@www ~]# ./nginx -s stop
[root@www ~]# pkill -9 nginx
#或者先查看进程号如下图,然后再 kill -QUIT 12357
[root@www ~]# ps -ef |grep nginx
[root@www ~]# kill -QUIT 12357
#重启
[root@www ~]# ./nginx -s reload
多说一句,关闭Nginx的几种方式,最简单粗暴的就是直接 pkill -9 nginx
或者先查看nginx的主进程,然后杀死进程也是可以,如下面图片:
直接进行 [root@www ~]# kill -QUIT 12357
10、查看是否启动成功
[root@www ~]# netstat -tunl |grep 80
至此,我们的nginx服务器安装已经结束,如果你在安装过程中有其它任何问题,请留言或到二当家博客上找到我,我们一起讨论。