常见web架构:

LAMP  =Linux+Apache+Mysql+PHP

LNMP  =Linux+Nginx+Mysql+PHP

 

nginx概述: 知道:1  不知道:2

Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理服务器。 Nginx 是由 Igor Sysoev(伊戈尔·塞索耶夫)为俄罗斯访问量第二的 rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。

Nginx能够选择高效的epoll(Linux2.6内核)作为网络I/O)模型,在高连接并发的情况下,Nginx是Apache服务器不错的替代品,它能够支持高达5000个并发连接数的响应,而内存、CPU等系统资源消耗却非常低,运行非常稳定。

 

rambler  [ˈræmblə(r)] 漫步者

 

互动:  cn 是中国域名后缀   ru是哪个国家的域名后缀 ?

http://www.rambler.ru/

Russia 俄罗斯   ['rʌʃə]  ru

杀手代号47

 

扩展:http://www.rambler.ru/  Rambler是俄罗斯门户网站。

 

 

 

nginx的官方网站:

http://nginx.org/en/download.html

Mainline version  主线版本

Stable version  稳定版本

Legacy versions  遗产版本 /历史版本

版本命名的常识:偶数为稳定,奇数是测试版或开发版本

 

 

Tengine概述:
Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。

官方网站:http://tengine.taobao.org/

 

Nginx和Apache的区别:

nginx或apache 服务器本身可以解析php文件吗?  可以:1 不可以:2

apache和nginx在处理php代码时有什么区别?

 

1:Nginx是通过php-fpm这个服务来处理php文件

2:Apache是通过libphp5.so这个模块来处理php文件

 

Nginx:

 

 

Apache:

总结:

Apache的libphp5.so随着apache服务器一起运行,而Nginx和php-fpm是各自独立运行,所以在运行过程中,Nginx和php-fpm都需要分别启动!

 

 

实战场景: 公司现在要上一台web服务器, 并发数据要达5000人同时在线。 这时应该选择apache或nginx ?  你选择哪个?

nginx相对于apache的优点: 
轻量级,同样起web 服务,比apache 占用更少的内存及资源 ;高并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx 能保持低资源低消耗高性能高度模块化的设计,编写模块相对简单社区活跃,各种高性能模块出品迅速

apache 相对于nginx 的优点: 
apache 超稳定 一般来说,需要并发性高的web 服务,用nginx 。如果不需要性能只求稳定,那就apache 。

nginx处理动态请求是鸡肋,一般动态请求要apache去做,nginx只适合静态和反向。

 

 

 

安装nginx

登录腾讯云主机: https://www.qcloud.com/

云主机装系统使用的镜像: 不是rhel.iso  用的是 centos.img  或 centos.qcow2

听风格, 开眼界 !

 

一、安装nginx时必须先安装相应的编译工具
[root@xuegod63 ~]#yum -y install gcc gcc-c++ autoconf automake  

gcc  c语言编译器

gcc-c++ c++语言编译器

autoconf automake  用于make编译的工具


[root@xuegod63 ~]#yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

zlib  :nginx提供gzip模块,需要zlib库支持
openssl :nginx提供ssl功能
pcre  :支持地址重写rewrite功能

 

安装nginx:

上传nginx软件包对

[root@VM_113_253_centos ~]# yum install lrzsz -y

 

[root@xuegod63 ~]# tar zxvf nginx-1.10.2.tar.gz

[root@xuegod63 ~]# cd nginx-1.10.2

 

[root@xuegod63 nginx-1.10.2]# useradd  -s /sbin/noligin    -M     nginx

#创建一个nginx用户

-s      指定登录shell

-M     不创建家目录

这个一招学到手:1

 

[root@xuegod63 nginx-1.10.2]# ./configure --prefix=/usr/local/nginx   --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module  --with-http_gzip_static_module  --with-pcre       #检查编译环境

参数说明:

--prefix=/usr/local/nginx       指定安装路径

--user=nginx --group=nginx    指定运行nginx进程的用户和组

--with-http_ssl_module         支持ssl加密

--with-http_realip_module      此模块支持显示真实来源IP地址,主要用于NGINX做前端负载均衡服务器使用

--with-http_gzip_static_module  这个模块指定压缩

--with-pcre                   此模块支持rewrite功能           

[root@xuegod63 nginx-1.10.2]# echo $?

0

 

编译和安装:

[root@xuegod63 nginx-1.10.2]# make -j 4    #编译,把源代码编译成可执行的二进制文件。

-j 4  #以4个进程同时编译

第一次听说:1

编译:mysql 内核 1个小时。  -j 4  20分钟。

 

[root@xuegod63 nginx-1.10.2]# make  install   #安装

 

nginx主要目录结构:

[root@VM_113_253_centos nginx-1.10.2]# ls /usr/local/nginx/

conf  html  logs  sbin

conf  #配置文件

html  #网站根目录

logs  #日志

sbin  #nginx启动脚本

 

 

启动nginx :

[root@xuegod63 ~]# /usr/local/nginx/sbin/nginx   

测试:

http://123.207.157.107/

 

 

实战2: nginx调优--隐藏版本信息

 

为什么要屏蔽nginx版本信息?

答:因为黑客可以扫描出nginx版本信息,可以查看对应的版本信息的漏洞,然后攻击

如何查nginx版本信息?

 

想知道百度使用什么web服务器? 不会:1  

 

查看nginx版本信息:

[root@xuegod63 ~]# curl -I www.baidu.com

 

[root@xuegod63 ~]#  curl -I www.tencent.com

 

Nginx 漏洞

 

 

[root@xuegod63 ~]# curl -I www.taobao.com

HTTP/1.1 302 Found

Server: Tengine  基于nginx做了二次开发

 

查看自己的服务器:

[root@VM_113_253_centos ~]# curl  -I 123.207.157.107

HTTP/1.1 200 OK

Server: nginx/1.10.2   #这里暴露了目标信息

 

彻底让版本等敏感信息消失

讲技术 时,你别走:1

[root@VM_113_253_centos nginx-1.10.2]# cd /root/nginx-1.10.2

[root@xuegod63 nginx-1.9.12]# vim src/core/nginx.h//目的更改源码隐藏软件名称和版本号

13行

#define NGINX_VERSION       "8.8.2"                 #此行修改的是你想要的版本号

#define NGINX_VER          "XWS/" NGINX_VERSION   #此行修改的是你想修改的软件名称

[root@xuegod63 nginx-1.9.12]# vim src/http/ngx_http_header_filter_module.c

修改HTTP头信息中的connection字段,防止回显具体版本号

改:49 static char ngx_http_server_string[] = "Server: nginx" CRLF;

为:49 static char ngx_http_server_string[] = "Server: XWS" CRLF;

 

这个文件定义了http错误码的返回,有时候我们页面程序出现错误,Nginx会代我们返回相应的错误代码,回显的时候,会带上nginx和版本号,我们把他隐藏起来

[root@xuegod63 nginx-1.9.12]# vim src/http/ngx_http_special_response.c

29行

static u_char ngx_http_error_full_tail[] =

"<hr><center>" NGINX_VER "</center>" CRLF

"</body>" CRLF

"</html>" CRLF

;

static u_char ngx_http_error_tail[] =

"<hr><center>XWS</center>" CRLF

"</body>" CRLF

"</html>" CRLF

;

 

需要重新进行nginx安装:

 [root@VM_113_253_centos ~]# /usr/local/nginx/sbin/nginx -s stop

[root@VM_113_253_centos ~]# rm -rf /usr/local/nginx/

[root@VM_113_253_centos nginx-1.10.2]# pwd

/root/nginx-1.10.2

[root@VM_113_253_centos nginx-1.10.2]# make clean

rm -rf Makefile objs

 

编译和安装:

[root@xuegod63 nginx-1.10.2]# ./configure --prefix=/usr/local/nginx   --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module  --with-http_gzip_static_module  --with-pcre  && make && make install

 

 

启动服务:[root@localhost nginx]# /usr/local/nginx/sbin/nginx

 

测试是否隐藏了版本和软件名

启动服务:[root@localhost nginx]# /usr/local/nginx/sbin/nginx

测试是否隐藏了版本和软件名

[root@xuegod63 ~]# curl -I 123.207.157.107

HTTP/1.1 200 OK

Server: XWS/8.8.2

 

或:

http://123.207.157.107/aaa.html

 

总结:

Nginx web服务器介绍

Nginx与apache的对比

实战1:在“腾讯云主机”上源码编译安装Nginx

实战2:Nginx调优之隐藏版本信息防止黑客扫描识别漏洞

Nginx 源码安装和调优的更多相关文章

  1. Nginx源码安装及调优配置

    导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优 ...

  2. Nginx源码安装及调优配置(转)

      导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前 ...

  3. nginx源码安装方法

    nginx源码安装方法 安装方法如下 1.安装nginx必要的源码依赖软件包. yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zli ...

  4. nginx 源码安装配置详解(./configure)

    在"./configure"配置中,"--with"表示启用模块,也就是说这些模块在编译时不会自动构建,"--without"表示禁用模块, ...

  5. nginx源码安装

    1,首先解决系统环境: 安装rpm包组{CentOS6 跟开发相关的包组:} a.  Development Tools #yum groupinstall "Development Too ...

  6. nginx 源码安装的重启命令

    源码安装nginx就面临这样的麻烦,不能使用service nginx restart 来重启nginx,没办法只能重新加载下nginx. #/usr/local/nginx/sbin/nginx - ...

  7. nginx源码安装教程(CentOS)

    1.说明 官方源码安装说明:http://nginx.org/en/docs/configure.html 源码包下载地址:http://nginx.org/en/download.html 版本说明 ...

  8. nginx 源码安装以及后续升级https

    事情的来源是,公司要将网站从http升级到https,由于历史遗留原因,才发现现有的nginx是通过源码安装的,并没有安装ssl模块,需要现安装sll模块,这个nginx是整个公司最前端的一个代理,涉 ...

  9. Nginx源码安装配置

    Nginx web服务器简介 Nginx ("engine x") 是一个高性能HTTP 和 反向代理 服务器.IMAP.POP3.SMTP 服务器. Nginx 是由 Igor ...

随机推荐

  1. BZOJ 4698 差分+后缀数组

    思路: 对所有序列差分一下 公共串的长度+1就是答案了 二分 扫一遍height即可,.. //By SiriusRen #include <cstdio> #include <cs ...

  2. E - A Trivial Problem(求满足x!的尾数恰好有m个0的所有x)

    Problem description Mr. Santa asks all the great programmers of the world to solve a trivial problem ...

  3. PHP 数组基础知识

    php 数组基础知识function abc($a,$b,$c = 0){ echo $a,$b,$c;}abc(1,3); //调用方法 ////可变参数function def(){ $arr = ...

  4. Linux系统下通过命令行对mysql数据进行备份和还原

    一.备份 1.进入mysql目录 cd /var/lib/mysql (进入mysql目录,根据安装情况会有差别) 2.备份 mysqldump -u root -p密码 数据库名 数据表名 > ...

  5. iconfont在ios(safari)中的坑

    最近公司决定将项目图标整体迁移到iconfont,按网上常规方法,在安卓.pc端都没问题,唯独在ios的safari浏览器及微信内置浏览器中,iconfont始终在正常位置向下偏移,导致图标错乱. 网 ...

  6. Python之global

    1 Global The global statement and its nonlocal cousin are the only things that are remotely like dec ...

  7. php实现非对称加密

    <?php /** * 使用openssl实现非对称加密 * * @since 2015-11-10 */ class Rsa { /** * 私钥 * */ private $_privKey ...

  8. .NET Core & EntityFrameworkCore

    前言 .NET Core 相比于 .NET Fromework 有跨平台.轻量化且开源的优势. 在使用 EntityFrameworkCore 的时候也遇到了很多问题,至于网络上的教程嘛...大部分都 ...

  9. buildroot的make menuconfig配置

    开始对buildroot 编译 [root@xxxxxx /data/sandbox/open_linux/buildroot] #make -j 20 Your Perl installation ...

  10. Java8自定义条件让集合分组

    /** * 将一个指定类型对象的集合按照自定义的一个操作分组: 每组对应一个List.最终返回结果类型是:List<List<T>> * * @param <T> ...