CentOS下编译安装nginx及配置缩略图插件的方法教程
相信大家都知道利用yum安装nginx非常方便,但是有些插件并不会默认安装,比如http_image_filter_module,因此我们需要编译安装nginx,已达到我们的目的。下面来看看详细的方法吧。
安装依赖
yuminstall-ypcre-devellibmxl2-devellibxslt-develgd-devel
安装nginx
wgethttp://nginx.org/download/nginx-1.9.1.tar.gz tar-xzvfnginx-1.9.1.tar.gz cdnginx-1.9.1 ./configure\ --user=nginx\ --group=nginx\ --with-http_ssl_module\ --with-http_spdy_module\ --with-http_realip_module\ --with-http_addition_module\ --with-http_xslt_module\ --with-http_image_filter_module\ --with-http_sub_module\ --with-http_auth_request_module\ --with-http_stub_status_module\ --with-http_gzip_static_module make makeinstall
安装完成后,可以使用如下命令来查看nginx安装的模块
[root@linux001~]#/usr/local/nginx/sbin/nginx-V nginxversion:nginx/1.9.1 builtbygcc4.4.720120313(RedHat4.4.7-11)(GCC) builtwithOpenSSL1.0.1e-fips11Feb2013 TLSSNIsupportenabled configurearguments:--user=nginx--group=nginx--with-http_ssl_module--with-http_spdy_module--with-http_realip_module--with-http_addition_module--with-http_xslt_module--with-http_image_filter_module--with-http_sub_module--with-http_auth_request_module--with-http_stub_status_module--with-http_gzip_static_module--with-http_image_filter_module
增加启动脚本
新建文件/etc/init.d/nginx,内容如下:
#!/bin/sh
#
#nginx-thisscriptstartsandstopsthenginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:nginx
#config:/etc/nginx/nginx.conf
#config:/usr/local/nginx/conf/nginx.conf
#pidfile:/usr/local/nginx/logs/nginx.pid
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
#Sourcenetworkingconfiguration.
./etc/sysconfig/network
#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0
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
make_dirs(){
#makerequireddirectories
user=`$nginx-V2>&1|grep"configurearguments:"|sed's/[^*]*--user=\([^]*\).*/\1/g'-`
if[-z"`grep$user/etc/passwd`"];then
useradd-M-s/bin/nologin$user
fi
options=`$nginx-V2>&1|grep'configurearguments:'`
foroptin$options;do
if[`echo$opt|grep'.*-temp-path'`];then
value=`echo$opt|cut-d"="-f2`
if[!-d"$value"];then
#echo"creating"$value
mkdir-p$value&&chown-R$user$value
fi
fi
done
}
start(){
[-x$nginx]||exit5
[-f$NGINX_CONF_FILE]||exit6
make_dirs
echo-n$"Starting$prog:"
daemon$nginx-c$NGINX_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}
stop(){
echo-n$"Stopping$prog:"
killproc$prog-QUIT
retval=$?
echo
[$retval-eq0]&&rm-f$lockfile
return$retval
}
restart(){
#configtest||return$?
stop
sleep1
start
}
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/null2>&1
}
case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q||exit7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||exit0
;;
*)
echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit2
esac
添加好/etc/init.d/nginx后,需要增加执行权限,然后就可以用脚本来启动、停止nginx了。
chmoda+x/etc/init.d/nginx /etc/init.d/nginxstart /etc/init.d/nginxstop /etc/init.d/nginxrestart /etc/init.d/nginxreload
或者以服务来启动、停止nginx。
servicenginxstart servicenginxstop servicenginxrestart servicenginxreload
设置自启动
chkconfig--addnginx chkconfig--level345on
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对毛票票的支持。