Nginx 安装
Nginx 安装与配置
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的功能
- Web 服务器
- 反向代理服务器
- 负载均衡服务器
- 缓存服务器
Nginx的优点
Nginx的优点如下:
(1)高并发:能支持1万~2万甚至更多的并发连接(静态小文件更强)。
(2)处理请求对服务器的内存消耗较少。
(3)内置对集群节点的健康性检查功能,但功能相对较弱。
(4)可以通过Cache插件实现缓存软件的功能
安装Nginx
下面介绍安装Nginx 前的环境准备以及安装的操作过程。
准备安装环境
1.安装Nginx 所需要的依赖库软件
yum install pcre pcre-devel make automake zlib zlib-devel gcc gcc-c++ libtool openssl openssl-devel wget -y
2.下载Nginx 软件
wget http://nginx.org/download/nginx-1.20.1.tar.gz
编译和安装Nginx
#创建nginx用户
[root@localhost ~]# useradd nginx -s /sbin/nologin -M
#解压安装包
[root@localhost ~]# tar nginx-1.20.1.tar.gz
[root@localhost ~]# cd nginx-1.20.1/
#开始编译安装
[root@localhost nginx-1.20.1]# ./configure \
> --user=nginx \
> --group=nginx \
> --prefix=/usr/local/nginx-1.20.1/ \
> --with-http_ssl_module \
> --with-http_sub_module \
> --with-http_stub_status_module \
> --with-http_gzip_static_module \
> --with-pcre
[root@localhost nginx-1.20.1]# make && make install
#建立软连接
[root@localhost nginx-1.20.1]# ln -s /usr/local/nginx-1.20.1/ /usr/local/nginx
[root@localhost nginx-1.20.1]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
#启动服务并检查
[root@localhost ~]# nginx -t
nginx: the configuration file /usr/local/nginx-1.20.1//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.20.1//conf/nginx.conf test is successful
[root@localhost ~]# nginx
[root@localhost ~]# ss -lntp |grep 80
LISTEN 0 128 *:80 *:* users:(("nginx",pid=7930,fd=6),("nginx",pid=7929,fd=6))
| --user=nginx | 指定程序运行时的用户 |
|---|---|
| --group=nginx | 指定程序运行时的用户组 |
| --prefix=/usr/local/nginx-1.20.1/ | 指定安装目录 |
| --with-http_ssl_module | 使其支持https(需已安装openssl) |
| --with-http_sub_module | 允许用一些其它文本替换Nginx相应中的一些文本 |
| --with-http_stub_status_module | 可以获取自上次启动以来的工作状态 |
| --with-http_gzip_static_module | 在线实时压缩输出数据流 |
| --with-pcre | 启用pcre库 |

浙公网安备 33010602011771号