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

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

安装依赖

?
1
yum install -y pcre-devel libmxl2-devel libxslt-devel gd-devel

安装 nginx

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 安装的模块

?
1
2
3
4
5
6
[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 , 内容如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/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 了。

?
1
2
3
4
5
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。

?
1
2
3
4
service nginx start
service nginx stop
service nginx restart
service nginx reload

设置自启动

?
1
2
chkconfig –add nginx
chkconfig –level 345 on

总结

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

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:惠普N54L安装群晖需要修改的硬件设置

2023-4-26 23:56:09

建站知识

小知识:详解Nginx配置文件

2023-4-27 1:04:12

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索