在CentOS 6.3 64bit上安装Nginx 1.8.0
生活随笔
收集整理的這篇文章主要介紹了
在CentOS 6.3 64bit上安装Nginx 1.8.0
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
根據(jù)工作需要,現(xiàn)在需要安裝nginx服務(wù)器,本來可以直接安裝別人制作好的rpm包的,但是本著愛折騰和時(shí)刻嘗鮮的精神,我決定從官網(wǎng)下載最新的nginx源碼來安裝,下面記錄了我的安裝過程。
下面的安裝假定是以root用戶登錄并執(zhí)行
1.安裝依賴庫(kù)
這些依賴庫(kù)主要有g(shù)++、gcc、openssl-devel、pcre-devel和zlib-devel?
yum -y install make gcc gcc-c++ glibc glibc-devel lsof ??
yum -y install pcre pcre-devel ?
yum -y install zlib zlib-devel ?
yum -y install openssl openssl--devel?
2.下載源碼包
cd /usr/local/src
wget -d "http://nginx.org/download/nginx-1.8.0.tar.gz"
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module?
make -j 4
make install
3.驗(yàn)證性啟動(dòng)nginx
注意,在沒有設(shè)置nginx為系統(tǒng)服務(wù)之前,這里僅是驗(yàn)證性的啟動(dòng)測(cè)試。使用下面的命令查看nginx可執(zhí)行程序的路徑
whereis nginx
一般默認(rèn)在/usr/local/nginx目錄下面
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx
4.添加nginx為系統(tǒng)服務(wù)
添加如下文件
注冊(cè) nginx 服務(wù)
chkconfig --add nginx
chkconfig --list nginx
假如查看到nginx服務(wù)在各種級(jí)別下,都沒有打開,可以再次使用下面的命令明確指出在不同級(jí)別下打開:
chkconfig --level 2345 nginx on
再次采用
chkconfig --list nginx
查看,是否在上述各級(jí)別下已經(jīng)打開。這里之所以要如此強(qiáng)調(diào),是希望在斷電后nginx服務(wù)能自動(dòng)重啟。
4.修改配置文件nginx.conf
service nginx configtest
service nginx reload
讓nginx在新的配置下運(yùn)行就可以了
5.安裝中出現(xiàn)的問題和錯(cuò)誤
因?yàn)閚ginx.conf中出現(xiàn)問題,顯示錯(cuò)誤如下:
nginx: [emerg] unknown directive "lua_shared_dict" in /usr/local/nginx/conf/nginx.conf:11
https://www.centos.bz/2012/12/openresty-nginx-block-cc-attack-deploy/
我暫時(shí)將它們注釋掉
下面的安裝假定是以root用戶登錄并執(zhí)行
1.安裝依賴庫(kù)
這些依賴庫(kù)主要有g(shù)++、gcc、openssl-devel、pcre-devel和zlib-devel?
yum -y install make gcc gcc-c++ glibc glibc-devel lsof ??
yum -y install pcre pcre-devel ?
yum -y install zlib zlib-devel ?
yum -y install openssl openssl--devel?
2.下載源碼包
cd /usr/local/src
wget -d "http://nginx.org/download/nginx-1.8.0.tar.gz"
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module?
make -j 4
make install
3.驗(yàn)證性啟動(dòng)nginx
注意,在沒有設(shè)置nginx為系統(tǒng)服務(wù)之前,這里僅是驗(yàn)證性的啟動(dòng)測(cè)試。使用下面的命令查看nginx可執(zhí)行程序的路徑
whereis nginx
一般默認(rèn)在/usr/local/nginx目錄下面
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx
4.添加nginx為系統(tǒng)服務(wù)
添加如下文件
vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6echo -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval
}
stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval
killall -9 nginx
}
restart() {configtest || return $?stopsleep 1start
}
reload() {configtest || return $?echo -n $"Reloading $prog: "killproc $nginx -HUP
RETVAL=$?echo
}
force_reload() {restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {status $prog
}
rh_status_q() {rh_status >/dev/null 2>&1
}
case "$1" instart)rh_status_q && exit 0$1;;stop)rh_status_q || exit 0$1;;restart|configtest)$1;;reload)rh_status_q || exit 7$1;;force-reload)force_reload;;status)rh_status;;condrestart|try-restart)rh_status_q || exit 0;;*) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"exit 2
esac
chmod +x /etc/init.d/nginx
注冊(cè) nginx 服務(wù)
chkconfig --add nginx
chkconfig --list nginx
假如查看到nginx服務(wù)在各種級(jí)別下,都沒有打開,可以再次使用下面的命令明確指出在不同級(jí)別下打開:
chkconfig --level 2345 nginx on
再次采用
chkconfig --list nginx
查看,是否在上述各級(jí)別下已經(jīng)打開。這里之所以要如此強(qiáng)調(diào),是希望在斷電后nginx服務(wù)能自動(dòng)重啟。
4.修改配置文件nginx.conf
主要是根據(jù)業(yè)務(wù)邏輯來配置nginx.conf,這里忽略具體內(nèi)容
service nginx configtest
service nginx reload
讓nginx在新的配置下運(yùn)行就可以了
5.安裝中出現(xiàn)的問題和錯(cuò)誤
因?yàn)閚ginx.conf中出現(xiàn)問題,顯示錯(cuò)誤如下:
nginx: [emerg] unknown directive "lua_shared_dict" in /usr/local/nginx/conf/nginx.conf:11
nginx: [emerg] unknown directive "rewrite_by_lua_file" in /usr/local/nginx/conf/nginx.conf:136
解決方法
這兩個(gè)報(bào)錯(cuò),是因?yàn)閚ginx.conf中添加了這兩個(gè)指令,將對(duì)應(yīng)配置及邏輯刪除就可以了。
參考鏈接https://www.centos.bz/2012/12/openresty-nginx-block-cc-attack-deploy/
我暫時(shí)將它們注釋掉
總結(jié)
以上是生活随笔為你收集整理的在CentOS 6.3 64bit上安装Nginx 1.8.0的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在CentOS 6.3 64bit上安装
- 下一篇: 解密ATS 4.2.3的缓存状态密码