1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      nginxproxy_pass反向代理配置實例分析

      本篇內(nèi)容主要講解“nginx proxy_pass反向代理配置實例分析”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“nginx proxy_pass反向代理配置實例分析”吧!

      在晉州等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供成都網(wǎng)站制作、成都網(wǎng)站建設 網(wǎng)站設計制作按需定制,公司網(wǎng)站建設,企業(yè)網(wǎng)站建設,品牌網(wǎng)站制作,營銷型網(wǎng)站建設,外貿(mào)網(wǎng)站制作,晉州網(wǎng)站建設費用合理。

      下面舉個小實例說明下:

      centos7系統(tǒng)庫中默認是沒有nginx的rpm包的,所以我們自己需要先更新下rpm依賴庫

      1)使用yum安裝nginx需要包括nginx的庫,安裝nginx的庫

      [root@localhost ~]# rpm -uvh http://nginx.org/packages/centos/7/noarch/rpms/nginx-release-centos-7-0.el7.ngx.noarch.rpm

      2)使用下面命令安裝nginx

      [root@localhost ~]# yum install nginx

      3)nginx配置

      [root@localhost ~]# cd /etc/nginx/conf.d/
      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
      }
       
      [root@localhost conf.d]# cat /var/www/html/index.html
      this is page of test!!!!

      4)啟動nginx

      [root@localhost ~]# service nginx start //或者使用 systemctl start nginx.service

      5)測試訪問(103.110.186.23是192.168.1.23機器的外網(wǎng)ip)

      [root@localhost conf.d]# curl http://192.168.1.23
      this is page of test!!!!

      看看下面幾種情況:分別用http://192.168.1.23/proxy/index.html進行訪問測試

      為了方便測試,先在另一臺機器192.168.1.5上部署一個8090端口的nginx,配置如下:

      [root@bastion-idc ~]# cat /usr/local/nginx/conf/vhosts/haha.conf
      server {
      listen 8090;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
      }
      [root@bastion-idc ~]# cat /var/www/html/index.html
      this is 192.168.1.5
      [root@bastion-idc ~]# /usr/local/nginx/sbin/nginx -s reload

      測試訪問(103.110.186.5是192.168.1.5的外網(wǎng)ip):

      [root@bastion-idc ~]# curl http://192.168.1.5:8090
      this is 192.168.1.5

      nginx proxy_pass反向代理配置實例分析

      192.168.1.23作為nginx反向代理機器,nginx配置如下:

      1)第一種情況:

      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
       
      location /proxy/ {
       proxy_pass http://192.168.1.5:8090/;
      }
      }

      這樣,訪問http://192.168.1.23/proxy/就會被代理到http://192.168.1.5:8090/。p匹配的proxy目錄不需要存在根目錄/var/www/html里面

      注意,終端里如果訪問http://192.168.1.23/proxy(即后面不帶"/"),則會訪問失敗!因為proxy_pass配置的url后面加了"/"

      [root@localhost conf.d]# curl http://192.168.1.23/proxy/
      this is 192.168.1.5
      [root@localhost conf.d]# curl http://192.168.1.23/proxy
      
      301 moved permanently
      
      

      301 moved permanently


      nginx/1.10.3

      頁面訪問http://103.110.186.23/proxy的時候,會自動加上"/”(同理是由于proxy_pass配置的url后面加了"/"),并反代到http://103.110.186.5:8090的結果

      nginx proxy_pass反向代理配置實例分析

      2)第二種情況,proxy_pass配置的url后面不加"/"

      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
       
      location /proxy/ {
       proxy_pass http://192.168.1.5:8090;
      }
      }
      [root@localhost conf.d]# service nginx restart
      redirecting to /bin/systemctl restart nginx.service

      那么訪問http://192.168.1.23/proxy或http://192.168.1.23/proxy/,都會失敗!

      這樣配置后,訪問http://192.168.1.23/proxy/就會被反向代理到http://192.168.1.5:8090/proxy/

      nginx proxy_pass反向代理配置實例分析

      3)第三種情況

      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
       
      location /proxy/ {
       proxy_pass http://192.168.1.5:8090/haha/;
      }
      }
      [root@localhost conf.d]# service nginx restart
      redirecting to /bin/systemctl restart nginx.service
      [root@localhost conf.d]# curl http://192.168.1.23/proxy/
      192.168.1.5 haha-index.html

      這樣配置的話,訪問http://103.110.186.23/proxy代理到http://192.168.1.5:8090/haha/

      nginx proxy_pass反向代理配置實例分析

      4)第四種情況:相對于第三種配置的url不加"/"

      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
       
      location /proxy/ {
       proxy_pass http://192.168.1.5:8090/haha;
      }
      }
      [root@localhost conf.d]# service nginx restart
      redirecting to /bin/systemctl restart nginx.service
      [root@localhost conf.d]# curl http://192.168.1.23/proxy/index.html
      192.168.1.5 hahaindex.html

      上面配置后,訪問http://192.168.1.23/proxy/index.html就會被代理到http://192.168.1.5:8090/hahaindex.html
      同理,訪問http://192.168.1.23/proxy/test.html就會被代理到http://192.168.1.5:8090/hahatest.html

      [root@localhost conf.d]# curl http://192.168.1.23/proxy/index.html
      192.168.1.5 hahaindex.html

      注意,這種情況下,不能直接訪問http://192.168.1.23/proxy/,后面就算是默認的index.html文件也要跟上,否則訪問失敗!

      nginx proxy_pass反向代理配置實例分析

      -------------------------------------------------------------------------------------
      上面四種方式都是匹配的path路徑后面加"/",下面說下path路徑后面不帶"/"的情況:

      1)第一種情況,proxy_pass后面url帶"/":

      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
       
      location /proxy {
       proxy_pass http://192.168.1.5:8090/;
      }
      }
      [root@localhost conf.d]# service nginx restart
      redirecting to /bin/systemctl restart nginx.service

      nginx proxy_pass反向代理配置實例分析

      nginx proxy_pass反向代理配置實例分析

      2)第二種情況,proxy_pass后面url不帶"/"

      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
       
      location /proxy {
       proxy_pass http://192.168.1.5:8090;
      }
      }
      [root@localhost conf.d]# service nginx restart
      redirecting to /bin/systemctl restart nginx.service
      [root@localhost conf.d]#

      這樣配置的話,訪問http://103.110.186.23/proxy會自動加上"/”(即變成http://103.110.186.23/proxy/),代理到192.168.1.5:8090/proxy/

      nginx proxy_pass反向代理配置實例分析

      3)第三種情況

      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
       
      location /proxy {
       proxy_pass http://192.168.1.5:8090/haha/;
      }
      }
      [root@localhost conf.d]# service nginx restart
      redirecting to /bin/systemctl restart nginx.service

      這樣配置的話,訪問http://103.110.186.23/proxy會自動加上"/”(即變成http://103.110.186.23/proxy/),代理到http://192.168.1.5:8090/haha/

      nginx proxy_pass反向代理配置實例分析

      4)第四種情況:相對于第三種配置的url不加"/"

      [root@localhost conf.d]# cat test.conf
      server {
      listen 80;
      server_name localhost;
      location / {
      root /var/www/html;
      index index.html;
      }
       
      location /proxy {
       proxy_pass http://192.168.1.5:8090/haha;
      }
      }
      [root@localhost conf.d]# service nginx restart
      redirecting to /bin/systemctl restart nginx.service

      nginx proxy_pass反向代理配置實例分析

      這樣配置的話,訪問http://103.110.186.23/proxy,和第三種結果一樣,同樣被代理到http://192.168.1.5:8090/haha/

      到此,相信大家對“nginx proxy_pass反向代理配置實例分析”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關內(nèi)容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!


      新聞名稱:nginxproxy_pass反向代理配置實例分析
      文章出自:http://www.ef60e0e.cn/article/ghespi.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        柳江县| 瑞安市| 田林县| 延安市| 南丰县| 绍兴县| 云龙县| 康保县| 阜新市| 炎陵县| 三原县| 鹿泉市| 高碑店市| 东山县| 勃利县| 赤峰市| 汶川县| 阿城市| 宁化县| 绵阳市| 安吉县| 枝江市| 永寿县| 会泽县| 外汇| 三江| 巴林右旗| 茌平县| 遂平县| 常州市| 海原县| 中山市| 雷州市| 新民市| 剑川县| 娱乐| 四平市| 新安县| 南平市| 富川| 祁阳县|