当前位置: 首页 > 编程笔记 >

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

蒲曦
2023-03-14
本文向大家介绍CentOS下编译安装nginx及配置缩略图插件的方法教程,包括了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

总结

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

 类似资料:
  • 本文向大家介绍CentOS下编译、安装与配置nginx,包括了CentOS下编译、安装与配置nginx的使用技巧和注意事项,需要的朋友参考一下 1. 安装nginx 1.1 选择稳定版本 我们编译安装nginx来定制自己的模块,机器CentOS 6.2 x86_64。首先安装缺少的依赖包: # yum -y install gcc gcc-c++ make libtool zlib zlib-de

  • 本文向大家介绍Centos下编译安装Nginx教程详解,包括了Centos下编译安装Nginx教程详解的使用技巧和注意事项,需要的朋友参考一下 一、安装nginx时必须先安装相应的编译工具 建立nginx 组 zlib:nginx提供gzip模块,需要zlib库支持 openssl:nginx提供ssl功能 pcre:支持地址重写rewrite功能 二、tar -zxvf nginx-1.2.8.

  • 本文向大家介绍CentOS 6.3安装配置Nginx方法,包括了CentOS 6.3安装配置Nginx方法的使用技巧和注意事项,需要的朋友参考一下 zhoulf 2013-02-09除夕夜 原创 安装说明 系统环境:CentOS-6.3 软件:nginx-1.2.6.tar.gz 安装方式:源码编译安装 安装位置:/usr/local/nginx 下载地址:http://nginx.org/en/

  • 本文向大家介绍CentOS 4.0安装配置Nginx的方法,包括了CentOS 4.0安装配置Nginx的方法的使用技巧和注意事项,需要的朋友参考一下 1.安装说明: 系统环境:CentOS-4.0 2.依赖的程序     (1). gzip module requires zlib library     (2). rewrite module requires pcre library    

  • 本文向大家介绍Centos 7.3下SQL Server安装配置方法图文教程,包括了Centos 7.3下SQL Server安装配置方法图文教程的使用技巧和注意事项,需要的朋友参考一下 以后工作都将与Linux打交道,对于.net忠实粉丝现在进入Linux还算幸运,因为.net core和asp.net core都已经跨平台了。今天没事想试试传说中的Linux Sql server是不是上手容易

  • 本文向大家介绍CentOS系统下MongoDB安装及配置教程,包括了CentOS系统下MongoDB安装及配置教程的使用技巧和注意事项,需要的朋友参考一下 一、准备工作: 运行yum命令查看MongoDB的包信息 (提示没有相关匹配的信息,) 说明你的centos系统中的yum源不包含MongoDB的相关资源,所以要在使用yum命令安装MongoDB前需要增加yum源,也就是在 /etc/yum.

  • 本文向大家介绍CentOS 6.4下编译安装MySQL5.6.14教程,包括了CentOS 6.4下编译安装MySQL5.6.14教程的使用技巧和注意事项,需要的朋友参考一下 概述: CentOS 6.4下通过yum安装的MySQL是5.1版的,比较老,所以就想通过源代码安装高版本的5.6.14。 正文: 一、卸载旧版本 使用下面的命令检查是否安装有MySQL Server rpm -qa | g

  • 本文向大家介绍Ubuntu下nginx编译安装参数配置,包括了Ubuntu下nginx编译安装参数配置的使用技巧和注意事项,需要的朋友参考一下 安装依赖库: 编译配置: 编译安装: