$sudo tar -zxvf zlib-1.2.11.tar.gz
$cd zlib-1.2.11 #此处源码目录/usr/src/zlib-1.2.11
$./configure
$make
$sudo make install
同理解压编译安装pcre,openssl
2.下载nginx1.12.2(http://nginx.org/en/download.html)
$sudo tar -zxvf nginx1.12.2.tar.gz
$cd nginx1.12.2
$
CC=gcc ./configure--prefix=/usr/local/nginx1.12.2 \
--http-client-body-temp-path=/var/ftp/tmp/nginx/client\
--http-proxy-temp-path=/var/ftp/tmp/nginx/proxy\
--http-fastcgi-temp-path=/var/ftp/tmp/nginx/fastcgi\
--http-uwsgi-temp-path=/var/ftp/tmp/nginx/uwsgi\
--http-scgi-temp-path=/var/ftp/tmp/nginx/scgi\
--http-log-path=/var/ftp/logs/nginx/access.log\
--error-log-path=/var/ftp/logs/nginx/error.log\
--pid-path=/var/ftp/logs/nginx/nginx.pid\
--lock-path=/var/ftp/logs/nginx/nginx.lock\
--user=nginx \
--group=nginx \
--with-openssl=/usr/src/openssl-1.1.0g \
--with-pcre=/usr/src/pcre-8.41 \
--with-pcre-jit \
--with-zlib=/usr/src/zlib-1.2.11\
--with-file-aio \
--with-http_ssl_module\
--with-http_v2_module\
--with-http_gzip_static_module\
--with-http_stub_status_module\
--with-threads \
--without-http_auth_basic_module\
--without-http_autoindex_module\
--without-mail_pop3_module\
--without-mail_imap_module\
--without-mail_smtp_module
$make
$sudo make install
3.创建nginx用户组和用户名
$sudo groupadd -f nginx
$sudo useradd -g nginx nginx
4.配置nginx.conf
修改PID=/run/nginx.pid #可用默认的
5.创建目录/var/ftp/tmp/nginx
$sudo mkdir -p /var/ftp/tmp/nginx
6.添加启动/etc/init.d/nginx
$sudo vim /etc/init.d/nginx
脚本:
#!/bin/bash
#
# nginx Start up the nginx server daemon
#
# chkconfig: 2345 55 25
# Description: starts and stops the nginx web server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: starts and stops the nginx web server
### END INIT INFO
# To install:
# copy this file to /etc/init.d/nginx
# shell> chkconfig --add nginx (RedHat)
# shell> update-rc.d -f nginx defaults (debian)
# To uninstall:
# shell> chkconfig --del nginx (RedHat)
# shell> update-rc.d -f nginx remove
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
NAME=nginx
DAEMON=/usr/local/nginx1.12.2/sbin/$NAME
CONFIGFILE=/usr/local/nginx1.12.2/conf/$NAME.conf
PIDFILE=/run/$NAME.pid
ULIMIT=10240
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
echo "Starting $NAME ..."
ulimit -SHn $ULIMIT
$DAEMON -c $CONFIGFILE
}
do_stop() {
echo "Shutting down $NAME ..."
kill `cat $PIDFILE`
}
do_reload() {
echo "Reloading $NAME ..."
kill -HUP `cat $PIDFILE`
}
case "$1" in
start)
[ ! -f "$PIDFILE" ] && do_start || echo "nginx already running"
echo -e ".\ndone"
;;
stop)
[ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
echo -e ".\ndone"
;;
restart)
[ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
do_start
echo -e ".\ndone"
;;
reload)
[ -f "$PIDFILE" ] && do_reload || echo "nginx not running"
echo -e ".\ndone"
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
7.根据脚本中的提示(ubuntu)
#update-rc.d -f nginx defaults
8.启动nginx
#/etc/init.d/nginx start
9.查看nginx进程是否启动来判断脚本是否有误
#ps -aux| grep nginx