1、下载

点击Nginx官网下载地址进行下载,本人要和公司保持一致,使用1.14.2版本,下载nginx-1.14.2.tar.gz压缩包。

2、解压

tar -zxvf nginx-1.14.2.tar.gz

3、创建用户

# 新增用户组
groupadd fordream
# 新增用户
useradd -G root -g fordream -d /home/nginx/ nginx

4、安装

# 环境准备1:安装gcc依赖
yum -y install gcc gcc-c++ autoconf automake make
# 环境准备2:安装pcre依赖、ssl依赖、zlib依赖
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
# 安装Nginx
# 1、--prefix 指定安装路径
# 2、--with-http_ssl_module 安装https模块,不需要则不加该选项
# 3、--with-stream 安装四层负载均衡模块,不需要则不加该选项
./configure --prefix=/home/nginx/nginx --with-http_ssl_module --with-stream

########################成功后输出########################
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/home/nginx/nginx"
  nginx binary file: "/home/nginx/nginx/sbin/nginx"
  nginx modules path: "/home/nginx/nginx/modules"
  nginx configuration prefix: "/home/nginx/nginx/conf"
  nginx configuration file: "/home/nginx/nginx/conf/nginx.conf"
  nginx pid file: "/home/nginx/nginx/logs/nginx.pid"
  nginx error log file: "/home/nginx/nginx/logs/error.log"
  nginx http access log file: "/home/nginx/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

# 看到上面输出后,执行make命令进行编译
make
# 编译完成后进行安装
make install

注意: 一定要安装上面两个插件,否则会报错,错误如下。

# 缺少gcc依赖报错
checking for OS
 + Linux 3.10.0-1127.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

# 缺少PCRE依赖报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

# 缺少sll报错
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

5、配置环境变量

# 编辑/etc/profile
vi /etc/profile

# 在最下面新增
# 配置Nginx环境变量
export NGINX_HOME=/home/nginx/nginx
export PATH=$NGINX_HOME/sbin:$PATH

# 重新使配置文件生效
source /etc/profile

# 检查是否安装成功
[root@localhost nginx]# nginx -v
nginx version: nginx/1.14.2

版权声明:本文为yaozw0112原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/yaozw0112/article/details/109315701