nginx是一个web网站常用的高性能http和反向代理服务器,其具有较好的并发能力,被网易、百度、腾讯、新浪等网站广泛使用。

一、 理论简介

1.首先弄清楚正向代理和反向代理

正向代理:代理客户端,替客户端收发请求,使真实的客户端对服务器不可见。如图所示,proxy和client同属于一个网络,对server透明

反向代理:代理服务器,提服务器收发请求,使真实的服务器对客户端不可见。如图所示,proxy和server同属于一个网络,对client透明

实际上proxy都是代为收发请求和响应,只是在结构上左右换了下,所以一个叫正向代理,另一个叫反向代理。

2.nginx的反向代理原理

如下图所示:nginx作为反向代理服务器接收来自客户端的http请求,然后将请求转发给内部网络的web服务器,同时接收来自web服务器的response结果,并返回给客户端。此时nginx代理服务器对外展现为一个服务器。

3.nginx的反向代理的作用

(1)负载均衡。nginx可以将来自客户端的请求均衡的分发到web服务器集群中的不同机器上进行处理,平衡集群中各个服务器的压力。这对于大访问量的web网站来说,是需要的。
(2)安全保障。客户端直接访问的不是提供内容的web服务器,为保护网站服务器提供了一层屏障,有利于保护网站的安全。
(3)加速web请求。nginx可以配置缓存,存储真实web服务器的某些资源和响应,减轻真实服务器的压力,同时加速web请求

二、 nginx-1.9.7 编译安装

下载地址: http://nginx.org/download/nginx-1.9.7.tar.gz

补充: 安装 nginx之前,需要先安装一些依赖包:gcc、pcre、zlib
a、nginx gzip模块需要zlib库
b、nginx rewrite模块需要pcre库
c、nginx ssl模块需要openssl库

1、安装必要依赖包
[root@mysql03 ~]# yum install -y pcre pcre-devel

centos 6.7 配置 yum 本地源 链接参考: http://blog.csdn.net/zhang123456456/article/details/56690945
2、 Nginx安装
[root@mysql03 ~]# ll nginx-1.9.7.tar.gz
-rw-r--r--. 1 root root 885562 Jun 14 21:46 nginx-1.9.7.tar.gz
[root@mysql03 ~]# tar zxvf nginx-1.9.7.tar.gz
[root@mysql03 ~]# cd nginx-1.9.7
-- 配置nginx安装选项
[root@mysql03 nginx-1.9.7]# ./configure --prefix=/usr/local/nginx
说明: 配置完毕后可以看到一个配置概要,概要中的5项必须都有了相应的库支持
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
##如果想要安装openssl模块,安装时需指定 ./configure --prefix=/usr/local/nginx --with-openssl=/root/openssl-1.0.2d ##
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library
-- 安装nginx
[root@mysql03 nginx-1.9.7]# make && make install
3、 检查安装是否正常
[root@mysql03 nginx-1.9.7]# cd /usr/local/nginx
[root@mysql03 nginx]# ll
total 16
drwxr-xr-x. 2 root root 4096 Jun 14 22:14 conf
drwxr-xr-x. 2 root root 4096 Jun 14 22:14 html
drwxr-xr-x. 2 root root 4096 Jun 14 22:14 logs
drwxr-xr-x. 2 root root 4096 Jun 14 22:14 sbin
-- 启动
[root@mysql03 nginx]# ./sbin/nginx #如果不能正常启动,可能是端口占用
[root@mysql03 nginx]# ps -ef|grep nginx
root 5212 1 0 22:17 ? 00:00:00 nginx: master process ./sbin/nginx
nobody 5213 5212 0 22:17 ? 00:00:00 nginx: worker process
root 5228 2359 0 22:20 pts/0 00:00:00 grep nginx
-- 访问
浏览器输入: http://10.219.24.26/ #ip换成自己的ip
看到以下页面内容,一切正常。
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

-- 关闭
[root@mysql03 nginx]# ./sbin/nginx -s stop
[root@mysql03 nginx]# ps -ef|grep nginx
root 5241 2359 0 22:25 pts/0 00:00:00 grep nginx

说明: http://www.cnblogs.com/zengkefu/p/5814793.html  部分参考,感谢作者

nginx之 nginx-1.9.7 编译安装、理论简介的更多相关文章

  1. luajit+nginx+上传模块+lua模块编译安装

    git clone https://github.com/fdintino/nginx-upload-module.git git clone https://github.com/openresty ...

  2. Nginx的平滑升级记录---适用于编译安装的Nginx

    一.查看自己的Nginx的版本号 [root@localhost sbin]# cd /usr/local/nginx/sbin/ [root@localhost sbin]# ls nginx [r ...

  3. Nginx编译安装(Centos)

    前言 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大 ...

  4. CentOS6编译安装PHP7+Nginx

    本文属于动手搭建PHP开发环境的一部分,更多点击链接查看. 本文以centos6为例. 安装PHP 下载 http://cn2.php.net/distributions/php-5.6.22.tar ...

  5. nginx编译安装

    Nginx编译安装 1.nginx官网:http://wiki.nginx.org/Install下载:http://nginx.org/en/download.html 2.编译安装# wget h ...

  6. 编译安装nginx并修改版本头信息—参考实例

    今天做实验的时候,想起我那台yum安装的nginx+php-fpm+mysql服务器上的nginx版本有点低了,并且还要加两个第3方模块,就去nginx官网下载了最新稳定版nginx-1.0.6,好了 ...

  7. nginx软件的编译安装步骤

    1.1 检查软件安装的系统环境 [root@web02 conf]# cat /etc/redhat-release CentOS release 6.8 (Final) [root@web02 co ...

  8. centOS linux 下nginx编译安装详解

    Nginx的官方网站是 www.nginx.org   Nginx的下载地址是:http://nginx.org/en/download.html   由 于官网的设计非常简洁不大气不上档次,所以我们 ...

  9. Centos7编译安装Nginx+keepalived

    一.安装环境.主机信息及软件版本 Nginx:1.12.2keepalived:2.0.12时间同步(同步后确认各服务器时间是否一致,不一致需要修改一下时区) 关闭防火墙 二.编译安装Nginx 1. ...

  10. Nginx监控-Nginx+Telegraf+Influxb+Grafana

    搭建了Nginx集群后,需要继续深入研究的就是日常Nginx监控. Nginx如何监控?相信百度就可以找到:nginx-status 通过Nginx-status,实时获取到Nginx监控数据后,如何 ...

随机推荐

  1. 配置树莓派3和局域网NTP服务器实现内网时间校准

    一.配置局域网NTP服务器 1.安装ntp-4.2.8p5-win32-setup.exe 下载地址:https://www.meinbergglobal.com/english/sw/ntp.htm ...

  2. 防止iframe被别的网站引用

    try{ top.location.hostname; if (top.location.hostname != window.location.hostname) { top.location.hr ...

  3. 20165101刘天野 2017-2018-2 《Java程序设计》第4周学习总结

    #20165101刘天野 2017-2018-2 <Java程序设计>第4周学习总结 教材学习内容总结 第五章:子类与继承 面向对象程序设计语言有三大特性:封装.继承和多态性.继承是面向对 ...

  4. 斯坦福机器学习视频笔记 Week8 无监督学习:聚类与数据降维 Clusting & Dimensionality Reduction

    监督学习算法需要标记的样本(x,y),但是无监督学习算法只需要input(x). 您将了解聚类 - 用于市场分割,文本摘要,以及许多其他应用程序. Principal Components Analy ...

  5. Docker 监控平台Prometheus

    Prometheus 是一个强大的监控平台,提供了监控数据搜集.存储.处理.可视化和告警一套完整的解决方案. 官方网站:https://prometheus.io

  6. poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】

                                                                                                         ...

  7. FIND_IN_SET的简单使用

    FIND_IN_SET(str,strlist)函数 str 要查询的字符串 strlist 字段名 参数以”,”分隔 如 (1,2,6,8) 查询字段(strlist)中包含(str)的结果,返回结 ...

  8. C#遍历指定文件夹中的所有文件

    DirectoryInfo TheFolder=new DirectoryInfo(folderFullName);//遍历文件夹foreach(DirectoryInfo NextFolder in ...

  9. 利用PushbackReader读取文件中某个字符串之前的内容

    package File; import java.io.FileReader; import java.io.IOException; import java.io.PushbackReader; ...

  10. Python创建插入数据库MySQL

    首先要在控制台创建好数据库 mysql -u root -p 创建数据库 查看数据库 -------------------更新分割线(上面为新增...太久没用都忘了SQL基本命令了)-------- ...