Linux(centos7.X)安装Nginx

本文档详细介绍了如何在CentOS7系统中安装Nginx,包括从官网下载1.14.2版本的Nginx,解压文件,创建服务用户,以及安装过程中的关键步骤和需要注意的依赖问题。
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值