Nginx安装
1 介绍
Nginx是一个高性能的HTTP、反向代理服务器。Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的, 第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置 文件和低系统资源的消耗而闻名。 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程 序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并 发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:新浪、网易、腾讯 等
主要功能:
反向代理
实现集群和负载均衡
静态资源虚拟化
Nginx的版本:
Nginx开源版 http://nginx.org/en/
官方原始的Nginx版本
Nginx plus商业版
开箱即用,集成了大量功能
Open Resty https://openresty.org/cn/
OpenResty是一个基于Nginx与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。更适用于需要大量二次开发的场景,有极强的扩展性
Tengine https://tengine.taobao.org/
由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。相比于Open Resty,扩展性不够强,但是能够满足绝多数使用场景
2 安装步骤
nginx安装包:
链接:https://pan.baidu.com/s/1EjWB_EF7VRtQuw11fvTkDQ?pwd=1111
提取码:1111
2.1 编译安装
./configure --prefix=/usr/local/nginx
make
make install
2.2 如果出现警告或报错
提示
checking for OS
+ Linux 3.10.0-693.el7.x86_64 x86_64 checking for C compiler ... not found
./configure:error:Ccompilerccisnotfound
安装gcc
yum install -y gcc
提示:
./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.
安装zlib库
yum -y install zlib zlib-devel
接下来执行
make
make install
2.3 启动Nginx
进入安装好的目录 /usr/local/nginx/sbin
./nginx 启动
./nginx -s stop 快速停止
./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求
./nginx -s reload 重新加载配置
2.4 安装成系统服务
创建服务脚本
vi /usr/lib/systemd/system/nginx.service
服务脚本内容
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载系统服务
systemctl daemon-reload
启动服务
systemctl start nginx.service
设置开机启动
systemctl enable nginx.service
评论区