ubuntu 16.04 编译安装ngnix过程

1.解决依赖库的问题:
dpkg -l | grep zlib #查看是否已安装zlib
apt-get install zlib1g-dev #安装zlib
apt-get install openssl libssl-dev #安装openssl
apt-get install libpcre3 libpcre3-dev #安装pcre
apt install libxml2-dev libxslt-dev python-dev
apt install gcc libpcre++-dev libssl-dev make \
libxml2-dev libxslt-dev libgd-dev libgeoip-dev \
libgoogle-perftools-dev libatomic-ops-dev libperl-dev


2.下载安装nginx:
wget http://nginx.org/download/nginx-1.12.0.tar.gz #下载较新的nginx稳定版本
tar -zxvf nginx-1.12.0.tar.gz
mv nginx-1.12.0/* /alidata/server/nginx #复制到安装目录
./configure --user=www --group=www --prefix=/alidata/server/nginx --conf-path=/alidata/server/nginx/conf/nginx.conf --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid --http-log-path=/alidata/log/nginx/access/access.log --error-log-path=/alidata/log/nginx/error.log --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_xslt_module --with-http_image_filter_module --with-http_image_filter_module --with-http_geoip_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-google_perftools_module --with-cpp_test_module --with-pcre --with-libatomic
make && make install  #安装完毕




3.nginx配置:

使用sysv-rc-conf(chkconfig)的方式管理nginx服务

首先添加nginx服务管理的脚本

#!/bin/sh
#
# 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/sbin/$NAME
LOCKFILE=/var/lock/subsys/nginx
CONFIGFILE=/etc/nginx/$NAME.conf
PIDFILE=/var/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 ..."
$DAEMON -s stop
}

do_reload() {
echo "Reloading $NAME ..."
$DAEMON -s reload
}

case "$1" in
start)
[ ! -f "$PIDFILE" ] && do_start || echo "nginx already running"
echo -e ".\ndone"
;;

stop)
do_stop || echo "nginx not running"
echo -e ".\ndone"
;;

reload)
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

给脚本添加执行权限


sudo chmod +x /etc/init.d/nginx


添加到开机自启动


sudo sysv-rc-conf nginx on(这一步实际上就是实现了一个链接)


加载安装服务


sudo systemctl enable nginx(如果不愿意重启的话)


启动nginx服务


sudo service nginx start


测试nginx
curl localhost




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值