ngixn官网地址:http://nginx.org/en/download.html
1、下载源码:wget http://nginx.org/download/nginx-1.20.2.tar.gz
Mainline version:主线版本,即开发版本
Stable version:稳定版本
Legacy versions:以前的版本
2、解压
tar -zxvf nginx-1.20.2.tar.gz
3、安装依赖
yum -y install make zlib zlib-devel gcc-c++ openssl openssl-devel wget pcre pcre-devel git
4、进入解压出来的nginx目录,在当前目录执行configure进行检查,这里加上了两个模块
./configure --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module
注:–prefix= 指定编译安装目录
5、对nginx进行编译,在nginx解压目录中执行make
make
6、安装
make install
7、安装完成,查看结果
./nginx -V
8、nginx启动加入service
touch /etc/init.d/nginx
chmod +x /etc/init.d/nginx
#!/bin/bash
#tartup script for the nginx Web Server
nginx=/data/nginx/sbin/nginx
conf=/data/nginx/conf/nginx.conf
case $1 in
start)
echo "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo "Stopping Nginx"
$nginx -s stop
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
9、启动、停止、重启
service nginx start/stop/restart