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