一、实验环境
二、实验步骤
Nginx:
1.安装环境
yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel
2.创建程序用户,将包拖入并解压到/usr/src
useradd -s /sbin/nglogin nginx
cd /usr/src
将nginx-goodies-nginx-sticky-module-ng-08a395c66e42.tar.gz、ngx_cache_purge-2.3.tar.gz、nginx-1.12.0.tar.gz包拖入
tar xf nginx-goodies-nginx-sticky-module-ng-08a395c66e42.tar.gz (谷歌第三方工具:绑定后台服务器)
tar xf ngx_cache_purge-2.3.tar.gz(缓存刷新模块)
tar xf nginx-1.12.0.tar.gz
3.编译安装
cd nginx-1.12.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx \
--with-http_stub_status_module --with-http_realip_module --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi --with-pcre --add-module=../ngx_cache_purge-2.3 --with-http_flv_module --add-module=../nginx-goodies-nginx-sticky-module-ng-08a395c66e42 && make && make install
4.创建软链接,创建目录给予权限
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
mkdir -p /var/tmp/nginx/client
chown -R nginx:nginx /var/tmp/nginx
5.添加脚本给予执行权限
vim /etc/init.d/nginx
添加:
#!/bin/bash
# chkconfig: 2345 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
netstat -anplt |grep ":80" &> /dev/null && pgrep "nginx" &> /dev/null
if [ $? -eq 0 ]
then
echo "Nginx service already running."
else
$PROG -t &> /dev/null
if [ $? -eq 0 ] ; then
$PROG
echo "Nginx service start success."
else
$PROG -t
fi
fi
;;
stop)
netstat -anplt |grep ":80" &> /dev/null && pgrep "nginx" &> /dev/null
if [ $? -eq 0 ]
then
kill -s QUIT $(cat $PIDF)
echo "Nginx service stop success."
else
echo "Nginx service already stop"
fi
;;
restart)
$0 stop
$0 start
;;
status)
netstat -anplt |grep ":80" &> /dev/null && pgrep "nginx" &> /dev/null
if [ $? -eq 0 ]
then
echo "Nginx service is running."
else
echo "Nginx is stop."
fi
;;
reload)
netstat -anplt |grep ":80" &> /dev/null && pgrep "nginx" &> /dev/null
if [ $? -eq 0 ]
then
$PROG -t &> /dev/null
if [ $? -eq 0 ] ; then
kill -s HUP $(cat $PIDF)
echo "reload Nginx config success."
else
$PROG -t
fi
else
echo "Nginx service is not run."
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
chmod +x /etc/init.d/nginx
6.添加到系统服务
chkconfig --add nginx
chkconfig nginx on
7.启动nginx
netstat -anpt|grep nginx
查看到80端口开启
8.使用浏览器访问nginx服务(win10)