随笔 - 19  文章 - 0  评论 - 0  阅读 - 1601

nginx笔记第二章(高级篇)--1--

一、基础回顾

        

 

 

 

 

 

              

 

              

              

 

 

二、nginx负载均衡(默认为轮询【就是挨个访问】模式)

     1.权重weight(其中down为停用,backup为备用)

              

      2.其他均衡策略

              

 

 

 

三、扩容

      

 

 

1.水平扩展:集群化(集群中保持会话)

  注意:大型企业一般用redis的做法保持会话,中小型项目用hash可行。

 (1)sticky模块【cookic形式保持会话模块】安装与使用

      ----------------------------------------------------------------------------------------点 击 进 入---------------------------------------------------------------------------------------------------

 keeplive的tcp连接保持设置

具体说明:https://blog.csdn.net/wzj_110/article/details/123909886

 

 

四、缓冲区

  1.上游服务端

            

        

  2.客户端限制

              

 

五、获取远程客户端真实IP设置

            proxy_set_header用来设定被代理服务器接收到的header信息

            语法:proxy_set_header field value;
            field :为要更改的项目,也可以理解为变量的名字,比如host
            value :为变量的值
            如果不设置proxy_set_header,则默认host的值为proxy_pass后面跟的那个域名或者IP(一般写IP)

 

            proxy_set_header X-Real-IP $remote_addr;
            和
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            用来设置被代理端接收到的远程客户端IP,如果不设置,则header信息中并不会透传远程真实客户端的IP地址。

            配置示例:

            server {
              listen 80;
              server_name www.xxx.com;
  
              location /aming/
                      {
                        proxy_pass http://192.168.1.10:8080/linux/;
                        proxy_set_header host $host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                      }
                }
              这段配置也是一般情况下,反向代理的标准配置。
              原文链接:https://blog.csdn.net/run65536/article/details/108556648

 六、gzip压缩

          

1.nginx动态压缩的gzip配置

                

                

 

    实例:

              gzip on;
              gzip buffers 16 8k;

              gzip comp_level 6;

              gzip http version 1.1;

              gzipmin length 256;

              gzip proded any;

              gzip vary on;

              gzip types    text/plain application/x-javascript text/ess application/xml;
              gzip_types

                  text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml

                  text/javascript application/javascript application/x-javascript
                  text/x-json application/json application/x-web-app-manifest+json

                  text/css text/plain text/x-component
                  font/opentype application/x-font-ttf application/vnd.ms-fontobject

                  image/x-icon;
              gzip_disable       "MSIE[1-6]\.(?!.*SV1)";

  2.nginx静态压缩的gzip配置  

 

                  解释:不通过gzip进行压缩,这样就能使用sendfile的高效文件传输,此需关闭gzip压缩,然后打开一个下面的参数即可

 

                  gzip_static on | off | always;:优先寻找与资源同名的gzip文件(如vue.js会先去寻找vue.js.gz)(on当用户浏览器支持gz文件时发送,always不论用户浏览器是否支持都发送)

             详细讲解:https://blog.csdn.net/weixin_46765649/article/details/127947412  

      (1)原生nignx没有 --with-http_gzip_static_module模块和 --with-http_gunzip_module解压模块

          ./configure   --prefix=/usr/local/nignx/    --with-http_gzip_static_module

          make

     (2)配置说明

         --with-http_gzip_static_module模块          --with-http_gunzip_module解压模块 

 

      

   3.Brotli第三方压缩模块(谷歌出的,比gzip快20%)

      尚硅谷2022版Nginx教程(亿级流量nginx架构设计)第81集有安装教程

     配置说明:--------------------------------------点击进入------------------------------------------

 

posted on   leiyunfeng  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示