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