1.9.7 编译安装、理论简介

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

一、 理论简介

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

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

1.9.7 编译安装、理论简介

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

1.9.7 编译安装、理论简介

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

2.nginx的反向代理原理

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

1.9.7 编译安装、理论简介

3.nginx的反向代理的作用

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

二、 nginx-1.9.7 编译安装

下载地址:

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

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

CentOS6.7 配置 yum 本地源 链接参考:

2、 Nginx安装
[root@linuxidc.com ~]# 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@linuxidc.com ~]# tar zxvf nginx-1.9.7.tar.gz
[root@linuxidc.com ~]# cd nginx-1.9.7
-- 配置nginx安装选项
[root@linuxidc.com 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@linuxidc.com nginx-1.9.7]# make && make install
3、 检查安装是否正常
[root@linuxidc.com nginx-1.9.7]# cd /usr/local/nginx
[root@linuxidc.com 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@linuxidc.com nginx]# ./sbin/nginx #如果不能正常启动,可能是端口占用
[root@linuxidc.com 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
-- 访问
浏览器输入: #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@linuxidc.com nginx]# ./sbin/nginx -s stop
[root@linuxidc.com nginx]# ps -ef|grep nginx
root 5241 2359 0 22:25 pts/0 00:00:00 grep nginx

CentOS 7下Nginx服务器的安装配置 

CentOS上安装Nginx服务器实现虚拟主机和域名重定向 

CentOS 6.8 安装LNMP环境(Linux+Nginx+MySQL+PHP) 

Linux下安装PHP环境并配置Nginx支持php-fpm模块 

Nginx服务的SSL认证和htpasswd认证 

Linux中安装配置Nginx及参数详解 

Nginx日志过滤 使用ngx_log_if不记录特定日志

CentOS 7.2下Nginx+PHP+MySQL+Memcache缓存服务器安装配置 

CentOS6.9编译安装Nginx1.4.7 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/2e70c6f27659bd58133eebf7dece2318.html