CentOS下編譯安裝nginx及配置縮略圖插件的方法教程
相信大家都知道利用yum安裝nginx 非常方便,但是有些插件并不會(huì)默認(rèn)安裝,比如 http_image_filter_module, 因此我們需要編譯安裝 nginx,已達(dá)到我們的目的。下面來(lái)看看詳細(xì)的方法吧。
安裝依賴(lài)
yum install -y pcre-devel libmxl2-devel libxslt-devel gd-devel
安裝 nginx
wget http://nginx.org/download/nginx-1.9.1.tar.gz tar -xzvf nginx-1.9.1.tar.gz cd nginx-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 make install
安裝完成后,可以使用如下命令來(lái)查看 nginx 安裝的模塊
[root@linux001 ~]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.9.1 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --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
增加啟動(dòng)腳本
新建文件 /etc/init.d/nginx , 內(nèi)容如下:
#!/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: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/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
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
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/null 2>&1
}
case "$1" in
start)
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
添加好 /etc/init.d/nginx 后,需要增加執(zhí)行權(quán)限,然后就可以用腳本來(lái) 啟動(dòng)、停止 nginx 了。
chmod a+x /etc/init.d/nginx /etc/init.d/nginx start /etc/init.d/nginx stop /etc/init.d/nginx restart /etc/init.d/nginx reload
或者以服務(wù)來(lái) 啟動(dòng)、停止 nginx。
service nginx start service nginx stop service nginx restart service nginx reload
設(shè)置自啟動(dòng)
chkconfig --add nginx chkconfig --level 345 on
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
- CentOS 7.3.1611編譯安裝Nginx1.10.3+MySQL5.7.16+PHP7.1.2
- CentOS 7下編譯安裝Nginx 1.11.10教程
- Centos6.4 編譯安裝 nginx php的方法
- Centos 6.8編譯安裝LNMP環(huán)境(Nginx+MySQL+PHP)教程
- Centos7下編譯安裝配置Nginx+PHP+MySql環(huán)境
- CentOS 6.5編譯安裝Nginx 1.10.2+MySQL 5.5.52+PHP5.5.38
- Centos下編譯安裝Nginx教程詳解
- CentOS 7.2.1511 編譯安裝Nginx1.10.1+MySQL5.6.33+PHP5.6.26運(yùn)行環(huán)境
- CentOS 7.2.1511 編譯安裝Nginx1.10.1+MySQL5.7.14+PHP7.0.11
- CentOS 7.0編譯安裝lnmp教程(Nginx1.6.0+MySQL5.6.19+PHP5.5.14)
- CentOS 6.6服務(wù)器編譯安裝lnmp(Nginx1.6.2+MySQL5.6.21+PHP5.6.3)
- CentOS 7.2 下編譯安裝PHP7.0.10+MySQL5.7.14+Nginx1.10.1的方法詳解(mini版本)
- CentOS 7.x編譯安裝Nginx1.10.3+MySQL5.7.16+PHP5.2 5.3 5.4 5.5 5.6 7.0 7.1多版本全能環(huán)境
相關(guān)文章
nginx 多個(gè)location轉(zhuǎn)發(fā)任意請(qǐng)求或訪問(wèn)靜態(tài)資源文件的實(shí)現(xiàn)
這篇文章主要介紹了nginx 多個(gè)location轉(zhuǎn)發(fā)任意請(qǐng)求或訪問(wèn)靜態(tài)資源文件的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
詳解通過(guò)Nginx部署Django(基于ubuntu)
這篇文章主要介紹了詳解通過(guò)Nginx部署Django(基于ubuntu),Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比較常見(jiàn)的一種方式,有興趣的可以了解一下。2017-01-01
Nginx搶購(gòu)限流配置實(shí)現(xiàn)解析
這篇文章主要介紹了Nginx搶購(gòu)限流配置實(shí)現(xiàn)解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08
使用Nginx代理MySQL連接并限制可訪問(wèn)IP配置
這篇文章主要為大家介紹了如何使用Nginx代理MySQL連接并限制可訪問(wèn)IP配置示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
Nginx使用if指令實(shí)現(xiàn)多個(gè)proxy_pass方式
這篇文章主要介紹了Nginx使用if指令實(shí)現(xiàn)多個(gè)proxy_pass方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
關(guān)于Nginx服務(wù)器可視化配置問(wèn)題
Nginx是一款輕量級(jí)的Web 服務(wù)器/反向代理服務(wù)器及電子郵件(IMAP/POP3)代理服務(wù)器,在BSD-like 協(xié)議下發(fā)行,這篇文章主要介紹了Nginx服務(wù)器可視化配置,需要的朋友可以參考下2022-10-10
zabbix配置nginx監(jiān)控的實(shí)現(xiàn)
本文主要介紹了zabbix配置nginx監(jiān)控的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05

