nginx的安装和简易的配置
虚拟机还原初始快照,网卡桥接,关防火墙和selinux
安装前提软件环境
yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel
复制nginx和缓存包到/usr/src,解压
useradd -s /sbin/nologin nginx //创建Nginx用户
cd /usr/src
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
编译安装nginx
cd /usr/src/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
添加nginx系统服务并启动
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #添加软链接 mkdir -p /var/tmp/nginx/client #创建文件夹 chown -R nginx:nginx /var/tmp/nginx #添加权限
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 #给脚本添加权限
chkconfig --add nginx
chkconfig nginx on
service nginx start #启动Nginx
查看版本 查看模块
nginx -v nginx -V