NGINX 之 编译安装方法 一
1、下载NGINX编译包
wget http://nginx.org/download/nginx-1.6.3.tar.gz
2、创建nginx软件所需的用户与组
[root@localhost software]# useradd www -s /sbin/nologin -M #不能登陆,不带家目录
[root@localhost software]# groupadd www #创建组
3、安装nginx所需要的依赖包
[root@localhost software]# yum -y install pcre pcre-devel gcc-c++ zlib-devel zlib open-ssl openssl-devel
4、开始安装NGINX
[root@localhost software]# tar -zxvf nginx-1.6.3.tar.gz
[root@localhost software]# cd nginx-1.6.3
[root@localhost nginx-1.6.3]# ./configure --user=www --group=www --with-http_ssl_module --prefix=/app/nginx-1.6.3
[root@localhost nginx-1.6.3]# make && make install
[root@localhost nginx-1.6.3]# ll /app/nginx-1.6.3/ #安装成功
总用量 16
drwxr-xr-x 2 root root 4096 7月 16 11:32 conf
drwxr-xr-x 2 root root 4096 7月 16 11:32 html
drwxr-xr-x 2 root root 4096 7月 16 11:32 logs
drwxr-xr-x 2 root root 4096 7月 16 11:32 sbin
5、查看nginx当前安装了那些模块
[root@localhost nginx-1.6.3]# ./sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
TLS SNI support enabled
configure arguments: --user=www --group=www --with-http_ssl_module --prefix=/app/nginx-1.6.3
6、给当前安装的NGINX添加一个新模块功能,如:状态模块--with-http_stub_status_module
[root@localhost nginx-1.6.3]# ./sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
TLS SNI support enabled
configure arguments: --user=www --group=www --with-http_ssl_module --prefix=/app/nginx-1.6.3
[root@localhost nginx-1.6.3]# cd /app/software/nginx-1.6.3 #返回到安装编译目录
[root@localhost nginx-1.6.3]# ./configure --user=www --group=www --with-http_ssl_module --prefix=/app/nginx-1.6.3 --with-http_stub_status_module
#添加--with-http_stub_status_module 模块
[root@localhost nginx-1.6.3]# make #编译生成二制制文件
[root@localhost nginx-1.6.3]# cp /app/nginx-1.6.3/sbin/nginx /app/nginx-1.6.3/sbin/nginx.bak #备份原有NGINX启动文件
[root@localhost nginx-1.6.3]# cp ./objs/nginx /app/nginx-1.6.3/sbin/nginx #替换为新编译生成的二制文件
cp:是否覆盖"/app/nginx-1.6.3/sbin/nginx"? y
[root@localhost nginx-1.6.3]# ./sbin/nginx -V #再次检查,已经有了--with-http_stub_status_module模块,添加成功
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
TLS SNI support enabled
configure arguments: --user=www --group=www --with-http_ssl_module --prefix=/app/nginx-1.6.3 --with-http_stub_status_module
7、制作系统服务
[root@localhost nginx-1.6.3]# vi /etc/init.d/nginx
脚本内容
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/app/nginx-1.6.3/sbin/nginx
nginx_config=/app/nginx-1.6.3/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
$nginxd -s reload
#if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`"
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
[root@localhost nginx-1.6.3]# chmod +x /etc/init.d/nginx
[root@localhost nginx-1.6.3]# chkconfig --dd /etc/init.d/nginx
[root@localhost init.d]# chkconfig nginx on
[root@localhost init.d]# service nginx stop
停止 nginx: [确定]
[root@localhost init.d]# service nginx start
正在启动 nginx: [确定]