CentOS 7 编译安装配置nginx教程

1 篇文章 0 订阅
1 篇文章 0 订阅

CentOS 7 nginx安装配置教程

nginx介绍:

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。
其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、简单的配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。

nginx版本说明和选择:

Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版;
Stable version:稳定版版本,生产环境上推荐使用的版本;
Legacy versions:之前发布的老版本的稳定版本。

nginx安装包下载地址:nginx官网下载地址

nginx安装

本文以nginx-1.18.0.tar.gz 为例,进行安装。
1.下载安装包
首先去官网下载nginx-1.18.0.tar.gz安装包,之后上传到服务器。
当然也可以直接去服务器用使用如下命令直接下载到本地服务器:

[root@node-01 ~]#  wget http://nginx.org/download/nginx-1.18.0.tar.gz

在这里插入图片描述
2.安装必要的支持库和编译工具
必要组件说明:
zlib:用于支持gzip模块
pcre:用于支持rewrite模块
openssl:用于支持ssl功能
gcc: 编译依赖 gcc 环境

[root@node-01 ~]# yum -y install make zlib zlib-devel pcre pcre-devel gcc-c++ libtool  openssl openssl-devel

3.编译安装nginx
首先将安装包直接解压到家目录下

[root@node-01 ~]# tar -zxvf nginx-1.18.0.tar.gz

进入安装包解压目录

[root@node-01 ~]# cd nginx-1.18.0

编译安装

[root@node-01 nginx-1.18.0]# ./configure \
> --prefix=/usr/local/nginx \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --pid-path=/var/run/nginx/nginx.pid \
> --lock-path=/var/lock/nginx.lock \
> --with-stream \
> --with-http_flv_module \
> --with-http_stub_status_module \
> --with-http_ssl_module \
> --with-stream_ssl_module \
> --with-http_gzip_static_module  \
> --with-file-aio \
> --with-http_realip_module \
> --with-pcre

确认输出结果是否正确

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/var/run/nginx/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/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"

编译安装
编译完成输出如下

 [root@node-01 nginx-1.18.0]# make && make install
 ...
 cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/var/run/nginx' \
        || mkdir -p '/var/run/nginx'
test -d '/var/log/nginx' \
        || mkdir -p '/var/log/nginx'
test -d '/usr/local/nginx/html' \
        || cp -R html '/usr/local/nginx'
test -d '/var/log/nginx' \
        || mkdir -p '/var/log/nginx'
make[1]: 离开目录“/root/nginx-1.18.0”

查看版本,验证是否安装成功

[root@node-01 nginx-1.18.0]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.18.0

nginx常用命令

./nginx -h # 查看命令帮助
./nginx -v # 查看nginx安装版本
./nginx -V # 查看安装版本和安装时配置信息
./nginx -s reload # 重新载入配置文件
./nginx -s reopen # 重启 Nginx
./nginx -s stop # 停止 Nginx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张折耳

此处应有打赏,就看兄弟你的了!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值