nginx實戰之nginx安裝教程
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