京东一面:如何用 Nginx 禁止国外 IP 访问网站!

作者:微信小助手

发布时间:2022-06-08T10:16:22

学最好的别人,做最好的自己

点击关注后端面试那些事Java面经都在这里

来源:toutiao.com/i6860736292339057156/


之前看了下 Nginx 的访问日志,发现每天有好多国外的 IP 地址来访问我的网站,并且访问的内容基本上都是恶意的。因此我决定禁止国外 IP 来访问我的网站。


想要实现这个功能有很多方法,下面我就来介绍基于 Nginx 的 ngx_http_geoip2 模块来禁止国外 IP 访问网站。


# 安装 geoip2 扩展依赖


        </ul>
        <pre class="code-snippet__js" data-lang="cs"><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">root@fxkj ~</span>]<span class="code-snippet__meta" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"># yum install libmaxminddb-devel -y</span></span></code></pre>
       </section>
      </section>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="outline: 0px;max-width: 100%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"># 下载 ngx_http_geoip2_module 模块</span></strong><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"></span></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <section class="code-snippet__fix code-snippet__js">
       <section class="code-snippet__fix code-snippet__js">
        <ul class="code-snippet__line-index code-snippet__js">
         
         
        </ul>
        <pre class="code-snippet__js" data-lang="cs"><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">root@fxkj tmp</span>]<span class="code-snippet__meta" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">#  git clone https://github.com/leev/ngx_http_geoip2_module.git</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">        [<span class="code-snippet__meta" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">ro tmp</span>]<span class="code-snippet__meta" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">#</span></span></code></pre>
       </section>
      </section>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">解压模块到指定路径</span></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">我这里解压到 /usr/local 目录下:</span></p>
      <section class="code-snippet__fix code-snippet__js">
       <section class="code-snippet__fix code-snippet__js">
        <ul class="code-snippet__line-index code-snippet__js">
         
         
         
         
         
         
         
         
        </ul>
        <pre class="code-snippet__js" data-lang="sql"><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">[root@fxkj&nbsp;tmp]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">#&nbsp;mv&nbsp;ngx_http_geoip2_module/&nbsp;/usr/local/</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">        [root@fxkj local]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"># ll ngx_http_geoip2_module/</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">        total 60</span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">        -rw-r<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">--r-- 1 root root  1199 Aug 13 17:20 config</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">        -rw-r<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">--r-- 1 root root  1311 Aug 13 17:20 LICENSE</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">        -rw-r<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">--r-- 1 root root 23525 Aug 13 17:20 ngx_http_geoip2_module.c</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">        -rw-r<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">--r-- 1 root root 21029 Aug 13 17:20 ngx_stream_geoip2_module.c</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">        -rw-r<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;">--r-- 1 root root  3640 Aug 13 17:20 README.md</span></span></code></pre>
       </section>
      </section>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"># 安装 nginx 模块</span></strong><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"></span></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">首先说明下环境,我的 nginx 版本是 1.16,在网上查了下安装 ngx_http_geoip2 模块至少需要 1.18 版本及以上,因此此次安装我是升级 nginx1.18,添加 ngx_http_geoip2 模块。</span></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">下载 nginx 1.18 版本:</span></p>
      <section class="code-snippet__fix code-snippet__js">
       <section class="code-snippet__fix code-snippet__js">
        <ul class="code-snippet__line-index code-snippet__js">
         
        </ul>
        <pre class="code-snippet__js" data-lang="cs"><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">root@fxkj&nbsp;~</span>]<span class="code-snippet__meta" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">#&nbsp;yum&nbsp;install&nbsp;libmaxminddb-devel&nbsp;-y</span></span></code></pre>
       </section>
      </section>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">解压 nginx1.18 软件包,并升级为 nginx1.18,添加 ngx_http_geoip2 模块。</span></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">需要注意:</span></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br></p>
      <ul class="list-paddingleft-1" style="padding-left: 1.5em;outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);overflow-wrap: break-word !important;">
       <li style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="outline: 0px;max-width: 100%;text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">升级 nginx,添加 nginx 模块,只需要编译,然后 make。不需要 make instll,不然线上的 nginx 会被新版本 nginx 完完整整的替换掉。</span></p></li>
       <li style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="outline: 0px;max-width: 100%;text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">编译前需要看下 nginx 当前安装了哪些模块。</span></p></li>
      </ul>
      <section class="code-snippet__fix code-snippet__js">
       <section class="code-snippet__fix code-snippet__js">
        <ul class="code-snippet__line-index code-snippet__js">
         
         
         
         
         
         
        </ul>
        <pre class="code-snippet__js" data-lang="sql"><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">[root@fxkj&nbsp;tmp]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">#&nbsp;/usr/local/nginx/sbin/nginx&nbsp;-V</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        nginx version: nginx/1.16.0</span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)</span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        built <span class="code-snippet__keyword" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">with</span> OpenSSL <span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">1.0</span><span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">.2</span>k-fips <span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">26</span> Jan <span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">2017</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        TLS SNI support enabled</span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        configure arguments: –<span class="code-snippet__keyword" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">with</span>-http_stub_status_module –prefix=/usr/<span class="code-snippet__keyword" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">local</span>/nginx –<span class="code-snippet__keyword" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">user</span>=nginx –<span class="code-snippet__keyword" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">group</span>=nginx –<span class="code-snippet__keyword" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">with</span>-http_ssl_module –<span class="code-snippet__keyword" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">with</span>-stream</span></code></pre>
       </section>
      </section>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p>
      <p style="outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;font-size: 16px;font-family: arial, helvetica, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">编译安装:</span></p>
      <section class="code-snippet__fix code-snippet__js">
       <section class="code-snippet__fix code-snippet__js">
        <ul class="code-snippet__line-index code-snippet__js">
         
         
         
         
         
         
         
         
         
         
         
        </ul>
        <pre class="code-snippet__js" data-lang="ruby"><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">[root@fxkj&nbsp;tmp]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">#&nbsp;tar&nbsp;-xf&nbsp;nginx-1.18.0.tar.gz</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        [root@fxkj tmp]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"># cd nginx-1.18.0/</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        [root@fxkj nginx-<span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">1.18</span>.<span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">0</span>]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"># ./configure --with-http_stub_status_module \</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        --prefix=<span class="code-snippet__regexp" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">/usr/local</span><span class="code-snippet__regexp" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">/nginx \</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        --user=nginx --group=nginx --with-http_ssl_module --with-stream \</span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        --add-module=/usr</span><span class="code-snippet__regexp" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">/local/ngx</span>_http_geoip2_module</span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        [root@fxkj nginx-<span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">1.18</span>.<span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">0</span>]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"># make</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        [root@fxkj nginx-<span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">1.18</span>.<span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">0</span>]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"># cp /usr/loca/nginx/sbin/nginx /usr/loca/nginx/sbin/nginx1.16    #备份</span></span></code><code style="white-space:pre-wrap;outline: 0px;max-width: 1000%;text-align: left;display: flex;font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">        [root@fxkj nginx-<span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">1.18</span>.<span class="code-snippet__number" style="outline: 0px;max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">0</span>]<span class="code-snippet__comment" style="outline: 0px;max-width: 1000%;box-sizing: border-box !impo