1,系统版本信息
cat /etc/kylin-release
nkvers
cat /proc/version
2,部署Nginx
2.1,安装Nginx所需依赖环境
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y2.2,下载Nginx 源码包并解压
#下载源码包
wget -c http://nginx.org/download/nginx-1.20.1.tar.gz
#解压至/opt目录
tar -zxvf nginx-1.20.1.tar.gz -C /opt
进入到解压目录
cd /opt/nginx-1.20.1/2.3,编译nginx 配置
./configure \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre2.4,编译安装
make -j2 && make install #预编译完成,开始编译及安装2.5,Nginx 配置文件目录
cd /usr/local/nginx初始安装完成,该目录只有4个文件夹:conf html logs sbin
2.6,启动Nginx
#进入sbin
cd sbin
#启动
./nginx -c /usr/local/nginx/conf/nginx.conf
#后面的-c参数是指定配置文件
#查看进程
ps -ef | grep nginx2.7,配置nginx开机启动
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true
[Install]
WantedBy=multi-user.targetsystemctl daemon-reload #重载启动文件
systemctl enable nginx.service #开机启动nginx
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #结束nginx
systemctl restart nginx.service #重启nginx
systemctl status nginx.service #查看nginx状态2.8,软链接
启动、重启、关闭都需要进入/usr/lcoal/nginx/sbin下目录通过./nginx 执行,更简单的办法就是创建一个软链接到/usr/bin/nginx
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx3,Nginx添加新的模块
在编译安装nginx完成后添加新模块
3.1,重新执行配置
./configure \
--with-file-aio --with-ipv6 --with-http_ssl_module \
--with-http_v2_module --with-http_realip_module \
--with-http_addition_module --with-http_sub_module \
--with-http_dav_module --with-http_flv_module \
--with-http_mp4_module --with-http_gunzip_module \
--with-http_gzip_static_module --with-http_random_index_module \
--with-http_secure_link_module --with-http_degradation_module \
--with-http_slice_module --with-http_perl_module=dynamic \
--with-http_auth_request_module --with-mail=dynamic \
--with-mail_ssl_module --with-pcre --with-pcre-jit \
--with-stream=dynamic --with-stream_ssl_module --with-debug3.2,执行make
make注意!千万别执行make install,不要会覆盖Nginx原有二进制包!!!
执行make完毕后,objs目录下会生成新的nginx执行文件
3.3,备份旧的nginx程序,并将新的nginx复制到原有安装目录
#备份旧的
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
# 复制新的nginx到/usr/local/nginx/sbin
cp -f /opt/nginx-1.20.1/objs/nginx /usr/local/nginx/sbin/nginx
cp: overwrite '/usr/local/nginx/sbin/nginx'? y3.4,测试新的nginx程序是否正确
cd /usr/local/nginx/sbin #进入/usr/local/nginx/sbin
./nginx -t3.5,重启nginx
./nginx -s reload3.6,查看模块是否已安装
nginx -V