您好,登錄后才能下訂單哦!
1.nginx簡介
常見WebServer(排行https://news.netcraft.com/archives/2018/, https://w3techs.com/technologies/overview/web_server/all )
老牌:Httpd(早期叫Apache) ,開源,市場份額最高
微軟:IIS
輕量:Lighttpd,性能高,低耗能,功能欠缺
Nginx誕生
2004年10月發布,俄國人Igor Sysoev開發,rambler.ru
Nginx官網、版本
nginx.org 1.14.0穩定版
國內分支Tengine(http://tengine.taobao.org/)
Nginx功能介紹
Http服務、反向代理、負載均衡、郵件代理、緩存加速、SSL、flv/mp4流媒體
2.nginx安裝-yum安裝
vi /etc/yum.repos.d/nginx.repo
#https://coding.net/u/aminglinux/p/nginx/git/blob/master/2z/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
yum install -y nginx
systemctl start/stop/restart/reload nginx
測試:瀏覽器訪問或者curl訪問
檢查服務進程:ps aux |grep nginx
檢查端口監聽:netstat -lnp |grep ‘:80’
有防火墻,需加規則iptables -I INPUT -p tcp --dport 80 -j ACCEPT
nginx -V查看版本以及各個目錄、參數
下面是我的腳本自動安裝的一個小模塊
OS_VERSION=rpm -q --queryformat '%{VERSION}' centos-release
echo "...............................................nginx................................................."
cp /root/tools/nginx.repo /etc/yum.repos.d/
sed -i "s/6/$OS_VERSION/g" /etc/yum.repos.d/nginx.repo
yum install -y nginx
yum install -y libselinux-python
yum install -y telnet nc
cp /root/tools/nginx.conf /etc/nginx/nginx.conf".bakdate +%F
"
cat /root/tools/nginx.conf > /etc/nginx/nginx.conf
if [[ "$OS_VERSION" = 6 ]]; then
setenforce 0 && chkconfig nginx on
elif [[ "$OS_VERSION" = 7 ]];then
setenforce 0 && systemctl enable nginx.service
fi
echo "................................................nginx...................................."
3.nginx安裝-源碼安裝
wget http://nginx.org/download/nginx-1.14.0.tar.gz //下載包
tar zxf nginx-1.14.0.tar.gz //解壓包
cd nginx-1.14.0
./configure --prefix=/usr/local/nginx //開始編譯安裝
make && make install
/usr/local/nginx/sbin/nginx //啟動
pkill nginx //殺死nginx進程,停止nginx服務
/usr/local/nginx/sbin/nginx -t //檢測配置文件語法錯誤
/usr/local/nginx/sbin/nginx -s reload//重載配置
服務管理腳本
https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx
系統啟動腳本
#!/bin/bash
. /etc/init.d/functions
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。