码迷,mamicode.com
首页 > 其他好文 > 详细

centos7.4编译安装nginx

时间:2017-10-29 23:23:18      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:编译 nginx

前言

    nginx作为后起之秀,最然目前市场份额现在远不足apache,但是从增长速度和发展前景来看,nginx是未来的趋势。具体数据可以参考https://www.netcraft.com/。截至到写博客的时间,全球的web server的占用率参考下图,可以看出明显的趋势。

技术分享


nginx的特性

    1、可针对静态资源高速并发访问及缓存

    2、可使用反向代理加速,并且可进行数据缓存

    3、具有简单负载均衡、节点健康检查和容错功能

    4、支持远程FastCGI服务的缓存加速

    5、支持FastCGI、Uwsgi、SCGI、Memcached Servers的加速和缓存

    6、支持SSL、TLS、SNI

    7、具有模块化的架构:过滤器包括gzip压缩、ranges支持、chunked响应、XSLT、SSI及图像缩放等功能。在SSI过滤器中,一个包含多个SSI的页面,如果经由FastCGI或反向代理处理,可被并行处理。

    8、同时具备其他web server的特性


nginx的特点

    1、基于异步网络I/O模型

    2、具备支持高性能,高并发的特性,并发连接可高达数万

    3、对小文件高并发支持很好,性能很高

    4、不支持类似Apache的DSO模式,扩展库必须编译进主程序(缺点)

    5、进程占用资源比较低

    6、支持Web、反向Proxy、Cache三大重点功能,并且都很优秀

    7、市场份额在逐年快速增加


为何nginx性能要强?

    nginx使用最新的epoll和kqueue异步网络I/O模型,而Apache使用的传统的select模型。目前Linux下能够承受高并发访问的Squid、Memcached软件采用的都是epoll模型。这里稍微给大家稍微介绍一下两者区别。

指标
selectepoll
性能随着连接数的增加性能急剧下降,处理成千上万并发连接数时,性能很差随着连接数的增加,性能基本上没有下降。处理成千上万并发连接时,性能很好
连接数连接数有限制,处理的最大连接数不超过1024。如果要处理的连接数超过1024个,需要重新编译连接数无限制
内在处理机制线性轮询回调callback

参考资料:《跟老男孩学Linux运维:Web集群实战》


编译安装nginx

    1、安装编译环境

]#yum install -y "development tools"
]#yum install -y pcre-devel
]#yum install -y openssl-devel

    2、通过官网下载相对应的源码。http://nginx.org/

    3、上传解压并根据需要修改参数

]#vim  src/http/ngx_http_header_filter_module.c
static u_char ngx_http_server_string[] = "Server: Apache" CRLF;   <===这里更改是server_tokens off的情况下显示的内容
]#vim src/core/nginx.h
#  define NGINX_VERSION      "2.4.2"               <===这里是更改默认的版本和名称
#  define NGINX_VER          "Tengine/" NGINX_VERSION
]#./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio ]#make && make install
]#vim /etc/profile.d/nginx.sh                     <===配置环境变量
  1 export PATH=/usr/local/nginx/sbin:$PATH
]#nginx                                 <===启动服务

为什么要修改这两个参数?先找个客户端测试一下

]#curl -I 192.168.32.112
HTTP/1.1 200 OK                        
Server: Tengine/2.4.2                            <===完美的隐藏了我们本身的web server,让攻击者蒙圈
Date: Sun, 29 Oct 2017 12:17:13 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 29 Oct 2017 10:22:52 GMT
Connection: keep-alive
ETag: "59f5abfc-264"
Accept-Ranges: bytes
]#vim /etc/nginx/nginx.conf                    
http{
    server_tokens off; 
}
]#curl -I 192.168.32.112
HTTP/1.1 200 OK
Server: Apache                                 <===关闭后显示的是src/http/ngx_http_header_filter_module.c中的名字,两种方法都可以进行隐藏实际的web server。提高安全性                                                       
Date: Sun, 29 Oct 2017 12:30:34 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 29 Oct 2017 10:22:52 GMT
Connection: keep-alive
ETag: "59f5abfc-264"
Accept-Ranges: bytes

centos7.4编译安装nginx

标签:编译 nginx

原文地址:http://maguofu.blog.51cto.com/12431016/1977209

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!