<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之旅 廣告
                正向代理是代理了用戶,反向代理是代理了服務器 ## **一、正向代理** 正向代理是指位于客戶端和目標服務器之間的代理服務器,客戶端必須明確指定代理服務器地址。客戶端發送的請求先經過代理服務器,再由代理服務器轉發給目標服務器。這樣,客戶端可以直接與目標服務器通信,而不需要了解代理服務器背后的[網絡](https://cloud.baidu.com/product/et.html)結構。 在Nginx中,要配置正向代理,需要在http或server配置塊中添加以下內容: ``` location / { proxy_pass http://目標服務器地址; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } ``` `proxy_pass`指令:指定了目標服務器的地址, `proxy_set_header`指令:用于設置請求頭信息 ![](https://img.kancloud.cn/d7/c2/d7c244199dbb5aa132fde68208f2fa24_349x269.png) ![](https://img.kancloud.cn/8f/21/8f21afba5393fafbf43e94a881a612da_703x395.png) ![](https://img.kancloud.cn/14/8e/148e0c7513510b622ca0b3904b73f5f2_984x536.png) 目標是gooogle服務器 電腦是客戶端 ## **二、反向代理** 反向代理與正向代理相反,它是將客戶端的請求轉發給后端服務器,并將后端服務器的響應返回給客戶端。客戶端不需要了解后端服務器的存在,反向代理服務器充當了客戶端和后端服務器之間的橋梁。 在Nginx中,要配置反向代理,需要在http或server配置塊中添加以下內容: ``` location / { proxy_pass http://后端服務器地址; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } ``` `proxy_pass`指令:指定了后端服務器的地址, `proxy_set_header`指令:用于設置請求頭信息。 ![](https://img.kancloud.cn/94/66/9466e2083fd99474b28d007cceef5aee_777x440.png) ![](https://img.kancloud.cn/b4/8f/b48fb12b2456c48b71a1a4054ef5fb4f_959x438.png) ### **1、反向代理實例一** 實現效果:使用 Nginx 反向代理,訪問`http://www.123.com`直接跳轉到 127.0.0.1:8080。 > 注意:此處如果要想從[http://www.123.com](https://link.zhihu.com/?target=http%3A//www.123.com)跳轉到本機指定的ip,需要修改本機的hosts文件。`192.168.17.129 www.123.com` 配置代碼 ~~~text server { listen 80; server_name 192.168.17.129; location / { root html; index index.html index.htm; proxy_pass http://127.0.0.1:8080 } } ~~~ 如上配置,我們監聽 80 端口,訪問域名為`http://www.123.com`(不加端口號時默認為 80 端口),故訪問該域名時會跳轉到 127.0.0.1:8080 路徑上。 >[info] 此處的意思為:nginx 反向代理服務監聽 192.168.17.129的80端口,如果有請求過來,則轉到proxy\_pass配置的對應服務器上,僅此而已。 ``` location / { proxy_pass http://127.0.0.1:48081;//瀏覽器的請求轉發到本機的48081端口 proxy_set_header Host $host;//瀏覽器輸入的地址會自動忽略端口,如瀏覽器是http://www.123.com:88則$host的值是www.123.com,瀏覽器是http://192.168.17.129:88則$host的值是192.168.17.129 proxy_set_header X-Real-IP $remote_addr;//客戶端(瀏覽器)的真實 IP 地址,傳遞給后端服務器 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; proxy_set_header X-Host $host:$server_port;//如果請求是通過http://www.123.com:88則$server_port是88;,所以`X-Host`會被設置為`www.123.com:88` proxy_set_header X-Scheme $scheme;//表示請求使用的協議(例如http或https) proxy_connect_timeout 30s; proxy_read_timeout 86400s; proxy_send_timeout 30s; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } ``` ### **2、反向代理實例二** 實現效果:使用 Nginx 反向代理,根據訪問的路徑跳轉到不同端口的服務中,Nginx 監聽端口為 9001。 * 訪問`http://127.0.0.1:9001/edu/`直接跳轉到 127.0.0.1:8081 * 訪問`http://127.0.0.1:9001/vod/`直接跳轉到 127.0.0.1:8082 第一步,需要準備兩個 tomcat,一個 8001 端口,一個 8002 端口,并準備好測試的頁面 第二步,修改 nginx 的配置文件,在 http 塊中配置 server ~~~text server { listen 9001; server_name 192.168.17.129; location ~ /edu/ { proxy_pass http://127.0.0.1:8080 } location ~ /vod/ { proxy_pass http://127.0.0.1:8081 } } ~~~ 根據上面的配置,當請求到達 Nginx 反向代理服務器時,會根據請求進行分發到不同的服務上。 [Nginx配置反向代理,一篇搞定! - 知乎 (zhihu.com)](https://zhuanlan.zhihu.com/p/451825018) ### **寶塔反向代理** ![](https://img.kancloud.cn/5f/e0/5fe03dd54f7bc62f7545eabbb81660e9_1606x1368.png) ~~~ #PROXY-START/ location ^~ / { proxy_pass http://127.0.0.1:8324; proxy_http_version 1.1; proxy_read_timeout 360s; proxy_redirect off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache set $static_fileLzXnun8E 0; if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" ) { set $static_fileLzXnun8E 1; expires 12h; } if ( $static_fileLzXnun8E = 0 ) { add_header Cache-Control no-cache; } } #PROXY-END/ ~~~
                  <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>

                              哎呀哎呀视频在线观看