<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # nginx模塊-負載均衡和反向代理 [TOC] ## 一、 簡單介紹 ### 1. 說明 1)功能說明 * ngx_http_proxy_module 反向代理模塊把用戶請求拋給服務器節點/池 * ngx_http_upstream_module 負載均衡模塊,實現網站的負載均衡和節點健康檢查 2)官方鏈接 [負載均衡](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream) [反向代理](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass ) ### 2. 語法 **1)負載均衡** ```sh Syntax: upstream name { ... } Context: http ``` eg: ```sh upstream oldboy { server 10.0.0.7:80; server 10.0.0.8:80; server 10.0.0.9:80; } ``` 說明:upstream模塊就類似定一個一個地址池或者說定一個web服務器組 **2)反向代理** ```sh Syntax: proxy_pass URL; Context: location, if in location, limit_except ``` eg: ```sh location / { proxy_pass http://upload; } ``` 說明:proxy_pass主要用于進行拋送用戶訪問請求給upstream模塊中的相應節點服務器 ## 二、 安裝配置 ### 1. yum安裝 ``` yum install nginx #需要阿里的epel源 egrep -v "#|^$" /etc/nginx/nginx.conf.default >/etc/nginx/nginx.conf ``` ### 2. 修改配置文件 ```sh cat /etc/nginx/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream noah { server 10.0.0.7:80; server 10.0.0.8:80; server 10.0.0.9:80; } server { listen 80; server_name localhost; root html; index index.html index.htm; location / { proxy_pass http://noah; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } } } ``` `upstream noah`和`location /`部分,為增加的反向代理和負載均衡模塊 proxy_set_header選項的解釋在最后面 ### 3. 啟動nginx ```sh nginx -t /etc/init.d/nginx start ``` ## 三、 檢測 ### 1. 利用瀏覽器進行測試 * 進行hosts解析 * 瀏覽以下網址`http://www.etiantian.org/oldboy.html ` * 利用ctrl+F5強制刷新測試 檢查是否進行負載調度 ### 2. 利用curl命令進行測試 ```sh [root@xxx ~]# curl -H host:www.etiantian.org 10.0.0.5/oldboy.html web01 www.etiantian.org [root@xxx ~]# curl -H host:www.etiantian.org 10.0.0.5/oldboy.html web02 www.etiantian.org [root@xxx ~]# curl -H host:www.etiantian.org 10.0.0.5/oldboy.html web03 www.etiantian.org ``` ## 四、 proxy_set_header解釋 1. `proxy_set_header Host $host`的作用: 將用戶的請求頭一起直接交給服務器,而不省略;在做負載均衡時要記得加此參數,否則可能可能導致以下問題: * 別名網址循環解析 * 有多個server標簽但卻只能解析第一個標簽的網址 * http版本會由1.1變為1.0,apache會不提供訪問 2. `proxy_set_header X-Forwarded-For $remote_addr`的作用: 將用戶的ip傳遞給web服務器,以便web服務器日志記錄用戶IP而非代理IP,需要日志格式中定義了http_x_forwarded_for選項
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看