CentOS下编译安装nginx及配置缩略图插件的方法教程

 更新时间:2017年02月03日 10:30:43   作者:不争  
这篇文章主要给大家介绍了在CentOS系统下编译安装nginx及配置缩略图插件的方法教程,文中给出了详细的安装步骤,对大家具有一定的参考价值,有需要的朋友们下面来一起看看吧。

相信大家都知道利用yum安装nginx 非常方便,但是有些插件并不会默认安装,比如 http_image_filter_module, 因此我们需要编译安装 nginx,已达到我们的目的。下面来看看详细的方法吧。

安装依赖

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

安装完成后,可以使用如下命令来查看 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

增加启动脚本

新建文件 /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: /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 后,需要增加执行权限,然后就可以用脚本来 启动、停止 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

或者以服务来 启动、停止 nginx。

service nginx start
service nginx stop
service nginx restart
service nginx reload

设置自启动

chkconfig --add nginx
chkconfig --level 345 on

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。

相关文章

  • nginx 多个location转发任意请求或访问静态资源文件的实现

    nginx 多个location转发任意请求或访问静态资源文件的实现

    这篇文章主要介绍了nginx 多个location转发任意请求或访问静态资源文件的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-11-11
  • 详解通过Nginx部署Django(基于ubuntu)

    详解通过Nginx部署Django(基于ubuntu)

    这篇文章主要介绍了详解通过Nginx部署Django(基于ubuntu),Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式,有兴趣的可以了解一下。
    2017-01-01
  • Nginx隐藏服务器端各类信息的方法

    Nginx隐藏服务器端各类信息的方法

    这篇文章主要介绍了Nginx隐藏服务器端各类信息的方法,包括隐藏HTTP头信息和PHP版本号等等,需要的朋友可以参考下
    2015-07-07
  • Nginx配置防盗链的完整步骤

    Nginx配置防盗链的完整步骤

    这篇文章主要给大家介绍了关于Nginx配置防盗链的完整步骤,文中通过示例代码介绍的非常详细,对大家学习或者使用Nginx具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-08-08
  • Nginx抢购限流配置实现解析

    Nginx抢购限流配置实现解析

    这篇文章主要介绍了Nginx抢购限流配置实现解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-08-08
  • nginx反向代理proxy_set_header

    nginx反向代理proxy_set_header

    这篇文章主要介绍了nginx反向代理proxy_set_header,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-06-06
  • 使用Nginx代理MySQL连接并限制可访问IP配置

    使用Nginx代理MySQL连接并限制可访问IP配置

    这篇文章主要为大家介绍了如何使用Nginx代理MySQL连接并限制可访问IP配置示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-08-08
  • Nginx使用if指令实现多个proxy_pass方式

    Nginx使用if指令实现多个proxy_pass方式

    这篇文章主要介绍了Nginx使用if指令实现多个proxy_pass方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-01-01
  • 关于Nginx服务器可视化配置问题

    关于Nginx服务器可视化配置问题

    Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行,这篇文章主要介绍了Nginx服务器可视化配置,需要的朋友可以参考下
    2022-10-10
  • zabbix配置nginx监控的实现

    zabbix配置nginx监控的实现

    本文主要介绍了zabbix配置nginx监控的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-05-05

最新评论