源码编译安装nginx

nginx编译安装

准备环境

centos7系统:192.168.124.204

关闭防火墙
关闭selinux

下载依赖包
yum -y install gcc gcc-c++ pcre pcre-devel gd-devel openssl openssl-devel zlib zlib-devel

yum -y install vim wget

创建nginx用户
useradd nginx

修改nginx用户登陆权限
vim /etc/passwd
在这里插入图片描述

编译安装

下载nginx (去官方找连接) 这里下载的是1.16版本的
[root@localhost local]# wget http://nginx.org/download/nginx-1.16.1.tar.gz

解压nginx包,进入安装包目录
[root@localhost ~]# tar xzf nginx-1.16.1.tar.gz -C /usr/local/

[root@localhost ~]# cd /usr/local/nginx-1.16.1/

然后进行编译
[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream

–with-stream nginx1.9以下版本不支持该模块

安装
[root@localhost nginx-1.16.1]# make && make install

创建文件目录
[root@localhost local]# mkdir /tmp/nginx/client_body -p

设置nginx启动脚本
[root@localhost local]# cat /etc/init.d/nginx

#! /bin/bash
# Description: Startup script for webserver on CentOS. cp it in /etc/init.d and
# chkconfig --add nginx && chkconfig nginx on
# then you can use server command control nginx
#
# chkconfig: 2345 08 99
# description: Starts, stops nginx

set -e
PATH=$PATH:/usr/local/nginx/sbin/
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/etc/nginx/nginx.conf
PIDFILE=/var/run/nginx.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

d_start() {
$DAEMON -c $CONFIGFILE || echo -n " already running"
}

d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}

d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0

修改nginx配置文件
[root@localhost local]# vim /etc/nginx/nginx.conf
修改pid位置

chmod 700 /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on

启动nginx
[root@localhost local]# systemctl restart nginx

访问192.168.124.204

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值