ubuntu 17.04源码安装nginx1.12.2并配置开机启动

1.准备zlib(zlib.net),pcre (pcre.org),openssl源码

$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


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值