centos下编译安装nginx

  1. 安装gcc环境
yum install gcc-c++
  1. 安装第三方依赖包
# pcre是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库
yum install pcre pcre-devel
# zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install zlib zlib-devel
# OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
yum install openssl openssl-devel
  1. 从官网下载安装包
wget http://nginx.org/download/nginx-1.14.2.tar.gz
  1. 解压并进入解压目录
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
  1. 创建makeFile文件
 ./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi1
  1. 安装
make && make install
  1. 创建临时文件
mkdir /var/temp/nginx/client -p
  1. 添加nginx用户
useradd -s /sbin/nologin -M nginx
  1. 添加环境变量
vim /etc/profile

在文件末尾添加:

 #添加nginx环境变量
 export NGINX_PATH=/usr/local/nginx
 export PATH=$PATH:$NGINX_PATH/sbin

使环境变量立即生效:

source /etc/profile
  1. 启动/关闭/重启 nginx
#启动
nginx
#关闭
nginx -s quit
#重启
nginx -s reload

猜你喜欢

转载自blog.csdn.net/qq_33562869/article/details/85239957