Ubuntu 16.04源码编译安装nginx 1.14.0
首页 /  linux开发 / ubuntu16.04.5编译安装nginx1.14.0

0 256

ubuntu16.04.5编译安装nginx1.14.0

Ubuntu 16.04源码编译安装nginx 1.14.0

ubuntu16.04.5编译安装nginx1.14.0_图一

一、下载相关的依赖库

pcre 下载地址 https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
openssl 下载地址 https://www.openssl.org/source/old/1.0.2/openssl-1.0.2g.tar.gz
zlib 下载地址 http://zlib.net/zlib-1.2.11.tar.gz
nginx 下载地址 http://nginx.org/download/nginx-1.14.0.tar.gz
可以下载到你的home /home/rongruo/files  rongruo改成你的home名

二、解压相关依赖库源码包

cd /home/rongruo/files
tar -zxf nginx-1.14.0.tar.gz 
tar -zxf pcre-8.42.tar.gz
tar -zxf zlib-1.2.11.tar.gz
tar -zxf openssl-1.0.2g.tar.gz

三、编译安装Nginx

cd /home/rongruo/files/nginx-1.14.0
./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/logs/nginx.pid --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --with-http_ssl_module --with-pcre=/tmp/pcre-8.42 --with-zlib=/tmp/zlib-1.2.11 --with-openssl=/tmp/openssl-1.0.2g
注:如果没有安装编译软件请安装,命令如下:
sudo apt-get install build-essential

四、执行make和make install 安装

make
sudo make install

五、验证nginx是否安装成功

执行结果:nginx version: nginx/1.14.0

六、启动nginx

sudo /usr/local/nginx/sbin/nginx

七、如果想用脚本启动的话 就需要写脚本

 sudo vim /etc/init.d/nginx

八、把如下代码复制到第七步里的 /etc/init.d/nginx

#!/bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/nginx/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
NGINXPID=/usr/local/nginx/logs
# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
	. /etc/default/nginx
fi

test -x $DAEMON || exit 0

set -e

. /lib/lsb/init-functions

test_nginx_config() {
	if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
		return 0
	else
		$DAEMON -t $DAEMON_OPTS
		return $?
	fi
}

case "$1" in
	start)
		echo -n "Starting $DESC: "
		test_nginx_config
		# Check if the ULIMIT is set in /etc/default/nginx
		if [ -n "$ULIMIT" ]; then
			# Set the ulimits
			ulimit $ULIMIT
		fi
		start-stop-daemon --start --quiet --pidfile $NGINXPID/$NAME.pid 
		    --exec $DAEMON -- $DAEMON_OPTS || true
		echo "$NAME."
		;;

	stop)
		echo -n "Stopping $DESC: "
		start-stop-daemon --stop --quiet --pidfile $NGINXPID/$NAME.pid 
		    --exec $DAEMON || true
		echo "$NAME."
		;;

	restart|force-reload)
		echo -n "Restarting $DESC: "
		start-stop-daemon --stop --quiet --pidfile 
		    $NGINXPID/$NAME.pid --exec $DAEMON || true
		sleep 1
		test_nginx_config
		start-stop-daemon --start --quiet --pidfile 
		    $NGINXPID/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
		echo "$NAME."
		;;

	reload)
		echo -n "Reloading $DESC configuration: "
		test_nginx_config
		start-stop-daemon --stop --signal HUP --quiet --pidfile $NGINXPID/$NAME.pid 
		    --exec $DAEMON || true
		echo "$NAME."
		;;

	configtest|testconfig)
		echo -n "Testing $DESC configuration: "
		if test_nginx_config; then
			echo "$NAME."
		else
			exit $?
		fi
		;;

	status)
		status_of_proc -p $NGINXPID/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
		;;
	*)
		echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
		exit 1
		;;
esac

exit 0

九、设置nginx执行权限

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

重启服务器,如果不重启的话 就得把nginx进程kill掉还有把nginx.pid删除掉才行
1. 查询nginx进程
ps -ef | grep nginx
sudo kill -9 进程号
sudo rm /usr/local/nginx/logs/nginx.pid
2.或者直接重启服务器吧
sudo shutdown -r now
3.重启nginx
sudo /etc/init.d/nginx restart

[来源] http://yuanmouren.erlyun.com/p.php?id=50

[声明] 本站资源来自用户分享,如损害你的权益请联系客服QQ:120074275给予处理。

容若 2018-11-26 17:58
10
送花
20积分一朵