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
      相關(guān)咨詢(xún)
      選擇下列產(chǎn)品馬上在線(xiàn)溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      Demo 1:基于域名的跳轉(zhuǎn)

      ? 應(yīng)用場(chǎng)景:原域名即將不可用,現(xiàn)用新的域名代替

      創(chuàng)新互聯(lián)建站是專(zhuān)業(yè)的龍門(mén)網(wǎng)站建設(shè)公司,龍門(mén)接單;提供成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行龍門(mén)網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!

      ? 理論結(jié)果:輸入舊域名,自動(dòng)跳轉(zhuǎn)到新域名,且其它參數(shù)不變

      DNS方向

      [root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm       //yum庫(kù)升級(jí)
      獲取http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
      警告:/var/tmp/rpm-tmp.zvmFF2: 頭V4 RSA/SHA1 Signature, 密鑰 ID 7bd9bf62: NOKEY
      準(zhǔn)備中...                          ################################# [100%]
      正在升級(jí)/安裝...
         1:nginx-release-centos-7-0.el7.ngx ################################# [100%]
      [root@localhost ~]# yum install nginx -y   #安裝nginx服務(wù)
      [root@localhost ~]# yum install bind -y
      [root@localhost ~]# vim /etc/named.conf 
      ###按照下面進(jìn)行修改
      options {
              listen-on port 53 { any; };           #監(jiān)聽(tīng)所有的53端口
              listen-on-v6 port 53 { ::1; };
              directory       "/var/named";
              dump-file       "/var/named/data/cache_dump.db";
              statistics-file "/var/named/data/named_stats.txt";
              memstatistics-file "/var/named/data/named_mem_stats.txt";
              recursing-file  "/var/named/data/named.recursing";
              secroots-file   "/var/named/data/named.secroots";
              allow-query     { any; };            #允許所有通過(guò)
      
      [root@localhost ~]# vim /etc/named.rfc1912.zones
      ####添加如下
      zone "test.com" IN {
              type master;
              file "named.test";
      };
      
      [root@localhost ~]# cp -p /var/named/named.localhost /var/named/named.test
      [root@localhost ~]# vim /var/named/named.test
      #####按照下面進(jìn)行修改
      $TTL 1D
      @       IN SOA  @ rname.invalid. (
                                              0       ; serial
                                              1D      ; refresh
                                              1H      ; retry
                                              1W      ; expire
                                              3H )    ; minimum
              NS      @
              A       127.0.0.1
      www IN  A       192.168.142.128
      
      [root@localhost ~]# systemctl start named
      [root@localhost ~]# systemctl stop firewalld.service 
      [root@localhost ~]# setenforce 0

      Nginx方向

      [root@localhost ~]# vim /etc/nginx/conf.d/default.conf
      ####按下面進(jìn)行更改
      server {
          listen       80;
          server_name  www.test.com;          #指定域名
      
          charset utf-8;                      #指定字符集
          access_log  /var/log/nginx/test.com-access.log  main;     #指定access日志文件位置
      
      [root@localhost ~]# systemctl start nginx
      [root@localhost ~]# netstat -atnp | grep nginx 
      tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4028/nginx: master

      此時(shí),能夠?qū)υ蛎M(jìn)行正常的訪(fǎng)問(wèn)

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      為了滿(mǎn)足實(shí)驗(yàn)要求,現(xiàn)對(duì)新域名添加dns區(qū)域

      [root@localhost ~]# vim /etc/nginx/conf.d/default.conf
      location / {
      ####在location后面添加下面兩行
              if ($host = 'www.test.com') {
                  rewrite ^/(.*)$ http://www.yun.com/$1 permanent;
              }
      
      [root@localhost ~]# vim /etc/named.rfc1912.zones
      ###為新域名增添新的dns區(qū)域
      zone "yun.com" IN {
              type master;
              file "named.yun";
      };
      
      [root@localhost ~]# cp -p /var/named/named.test /var/named/named.yun
      [root@localhost ~]# systemctl restart named
      [root@localhost ~]# systemctl restart nginx

      實(shí)驗(yàn)成功,成功從舊域名自動(dòng)跳轉(zhuǎn)到新域名

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      Demo 2:基于客戶(hù)端IP跳轉(zhuǎn)

      ? 應(yīng)用場(chǎng)景:網(wǎng)站維護(hù)時(shí)僅有個(gè)別用戶(hù)能夠正常進(jìn)行訪(fǎng)問(wèn),其余用戶(hù)僅能訪(fǎng)問(wèn)維護(hù)頁(yè)面

      ? 理論結(jié)果:一臺(tái)客戶(hù)機(jī)進(jìn)行訪(fǎng)問(wèn)時(shí)自動(dòng)進(jìn)行IP比對(duì),按表進(jìn)行分類(lèi)

      DNS方向

      ? 同Demo 1,不用進(jìn)行改變。

      Nginx方向

      [root@localhost ~]# vim /etc/nginx/conf.d/default.conf
      ####按下面進(jìn)行添加
          location / {
              root   /usr/share/nginx/html;
              index  index.html index.htm;
          }
      
         set $ip true;        #設(shè)定變量為true
         if ($remote_addr = "192.168.142.129") {           #匹配IP地址為“192.168.142.129”時(shí)
             set $ip false;                      #變量變更為false
         }
         if ($ip = true) {              #匹配變量為true時(shí)
             rewrite ^/(.*)$ /weihu.html;      #跳轉(zhuǎn)網(wǎng)頁(yè)到維護(hù)頁(yè)面
         }
         location = /weihu.html {       #匹配到維護(hù)頁(yè)面時(shí)
             root /usr/share/nginx/html;      #指定網(wǎng)頁(yè)站點(diǎn)
         }
      
      [root@localhost ~]# systemctl restart nginx

      此時(shí),根據(jù)不同的ip地址,將會(huì)瀏覽到不同的頁(yè)面(正常頁(yè)面/維護(hù)頁(yè)面)
      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      Demo 3:基于舊、新域名跳轉(zhuǎn)并添加目錄

      ? 應(yīng)用場(chǎng)景:將域名http://bbs.test.com下面的發(fā)帖都跳轉(zhuǎn)到 http://www.test.com/bbs,且域名跳轉(zhuǎn)后保持參數(shù) 不變

      [root@localhost ~]# vim /etc/nginx/conf.d/default.conf
      ###按照下面進(jìn)行修改,在location段下面添加
      location /new {
      #     if ($request_uri ~* ^/new) {
              rewrite /?(.*) http://www.test.com/bbs/$1 permanent;
      }
      
      [root@localhost ~]# systemctl restart nginx

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      Demo 4:基于參數(shù)匹配跳轉(zhuǎn)到指定頁(yè)面

      ? 應(yīng)用場(chǎng)景:用戶(hù)在輸入域名后,誤輸入了全為數(shù)字的錯(cuò)誤頁(yè)面,應(yīng)用后將自動(dòng)跳轉(zhuǎn)回指定頁(yè)面

      ? 理論結(jié)果:基于正則表達(dá)式的選擇

      DNS方向

      ? 同上面所有,無(wú)需進(jìn)行更改

      Nginx方向

      [root@localhost ~]# vim /etc/nginx/conf.d/default.conf
      ###按照下面進(jìn)行修改,在location段下面添加
      if ($request_uri ~* ^/(\d*).html$) {      #匹配以所有數(shù)字結(jié)尾的html文件
              rewrite (.*) http://www.test.com permanent;            #匹配零字或多字跳轉(zhuǎn)到網(wǎng)站主頁(yè)
          }
      
      [root@localhost ~]# systemctl restart nginx

      此時(shí),在域名后添加一段數(shù)字組成的html網(wǎng)頁(yè)將自動(dòng)跳轉(zhuǎn)回主頁(yè)。例:http://www.test.com/123456.htmlhttp://www.test.com/

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      Demo 5:基于PHP文件、具體頁(yè)面跳轉(zhuǎn)回首頁(yè)

      基于PHP文件

      [root@localhost ~]# vim /etc/nginx/conf.d/default.conf
      ###按照下面進(jìn)行修改
      ##location段后添加
      location ~* /upload/(.+)\.php$ {         #基于全部php文件
              rewrite (.*) http://www.test.com permanent;
          }
      
      [root@localhost ~]# systemctl restart nginx

      沒(méi)啥可說(shuō)的,以php的文件均會(huì)自動(dòng)跳轉(zhuǎn)回首頁(yè)

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)
      基于具體html頁(yè)面

      [root@localhost ~]# vim /etc/nginx/conf.d/default.conf
      ###按照下面進(jìn)行修改
      ##location段后添加
          location ~* /test.html$ {           #基于具體的html網(wǎng)頁(yè)
              rewrite (.*) http://www.test.com permanent;
          }
      
      [root@localhost ~]# systemctl restart nginx

      同上,訪(fǎng)問(wèn)某個(gè)具體網(wǎng)頁(yè)文件就會(huì)跳轉(zhuǎn)回首頁(yè)

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      基于任意的html頁(yè)面

      [root@localhost ~]# vim /etc/nginx/conf.d/default.conf
      ###按照下面進(jìn)行修改
      ##location /后面添加
          if ($request_uri ~* ^/new/(.+)\.html$) {          #匹配到任意html頁(yè)面
              rewrite (.*) http://www.test.com permanent;      #跳轉(zhuǎn)到首頁(yè)
           }
      
      [root@localhost ~]# systemctl restart nginx

      此時(shí),訪(fǎng)問(wèn)任意的html格式的網(wǎng)頁(yè)將自動(dòng)跳轉(zhuǎn)到首頁(yè)

      Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)

      感謝閱讀!!


      網(wǎng)頁(yè)標(biāo)題:Nginx服務(wù)——rewrite模塊應(yīng)用實(shí)戰(zhàn)
      網(wǎng)頁(yè)路徑:http://ef60e0e.cn/article/jgedds.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>

        盐山县| 太原市| 阳泉市| 临颍县| 长垣县| 六枝特区| 财经| 丰顺县| 友谊县| 镶黄旗| 枞阳县| 南漳县| 车险| 濉溪县| 灌云县| 呼和浩特市| 临沧市| 陆丰市| 含山县| 高密市| 阿城市| 行唐县| 灌云县| 霞浦县| 延吉市| 沁源县| 原平市| 卢湾区| 滕州市| 淮阳县| 循化| 康定县| 黄陵县| 吉林省| 宜阳县| 潞西市| 芮城县| 个旧市| 车险| 阿勒泰市| 宕昌县|