〇、下载离线软件包
或者自己手动去下载:
- 下载nginx: http://nginx.org/download/nginx-1.17.2.tar.gz
- 下载openssl: https://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
- 下载zlib: http://zlib.net/zlib-1.2.11.tar.gz
- 下载pcre: http://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
一、上传离线软件包
mkdir -p /usr/local/nginx/
将以上四个离线包上传到 此
二、安装
1.安装openssl
cd /usr/local/nginx
tar -zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install
2.安装pcre
cd /usr/local/nginx
tar -zxvf pcre-8.43.tar.gz
cd pcre-8.43
./configure && make && make install
3.安装zlib
cd /usr/local/nginx
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
4.安装nginx
cd /usr/local/nginx
tar zxvf nginx-1.17.2.tar.gz
cd nginx-1.17.2
./configure && make && make install
三、Nginx设置成服务并开机自动启动
1、在/etc/init.d下创建文件nginx
vim /etc/init.d/nginx
其内容如下:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
path="/usr/local/nginx/sbin"
name=nginx:
start() {
cd $path && nohup ./nginx >/dev/null 2>&1 &
sleep 1
pid1=`ps -ef | grep $name| grep -v grep |awk '{print $2}'`
if [[ -n $pid1 ]]; then
echo nginx 服务启动成功 pid=$pid1
fi
}
stop() {
pids=`ps -ef | grep $name | grep -v grep |awk '{print $2}'`
for pid in $pids
do
kill -9 $pid
echo pid=$pid[$name]已经关闭
done
}
restart()
{
$0 stop
sleep 1
$0 start
}
status()
{
ps -ef | grep $name | grep -v grep
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"命令行缺少: $0 {start|stop|restart|status}"
RETVAL=1
esac
exit $RETVAL
可能调整的配置:
path="/usr/local/nginx/sbin"
name=nginx:
也可以参照官方文档方式编写:Red Hat NGINX Init Script | NGINX
2、保存后执行【加入服务配置,开机启动】
chmod a+x /etc/init.d/nginx
chkconfig --add /etc/init.d/nginx
chkconfig nginx on
3、服务操作相关命令
service nginx start
service nginx stop
service nginx restart
service nginx status