1、nginx下载
1.1 联网下载如
wget http://nginx.org/download/nginx-1.9.4.tar.gz
1.2 本地上传服务器
2、依赖准备
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
3、进行configure配置
进入nginx目录执行脚本 ./configure --prefix=/usr/local/nginx
4、编译安装
make && make install
5、编写Nginx启动脚本,并加入系统服务
vim /etc/init.d/nginx
并在其中写入如下内容:
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|
restart|configtest}"
RETVAL=1
esac
exit $RETVAL
并更改文件的执行权限:chmod 755 /etc/init.d/nginx
加入系统服务启动列表 :chkconfig --add nginx
并使开机启动:chkconfig nginx on
开启服务 : service nginx start
6、不编写脚本操作nginx方法
首先进入nginx的sbin目录
./nginx -c /usr/local/nginx/conf/nginx.conf -s stop(停止)
./nginx -c /usr/local/nginx/conf/nginx.conf -s start(启动)
./nginx -c /usr/local/nginx/conf/nginx.conf (启动)
./nginx -c /usr/local/nginx/conf/nginx.conf -s reload (重新加载配置文件)
7、如何快速解除端口占用并杀死占用端口的进程
fuser -k 7080/tcp