主頁 > 知識庫 > nginx配置偽靜態(tài)和適配客戶端的方法步驟

nginx配置偽靜態(tài)和適配客戶端的方法步驟

熱門標簽:東莞人工智能電銷機器人供應商 金融行業(yè)外呼線路 高德地圖標注無營業(yè)執(zhí)照 長沙開福怎么申請400電話 智能電話機器人線路 江蘇電銷外呼防封系統(tǒng)是什么 廣州電銷機器人系統(tǒng)圖 賀州市地圖標注app 百度地圖標注要不要錢

后端用的thinkphp3.2.3框架,如果您是其他的語言或者,注意適當修改下

server {
    listen    80;
    server_name www.morgen.club;

    #charset koi8-r;
    
    #access_log logs/host.access.log main;

網站根目錄

    location / {
      root  html;
      index index.html index.htm;
      #設置訪問設備
      set $source_device 'index';
      #判斷為手機客戶端或ipad
      if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        set $source_device 'phone';
      }
      #根目錄
      if ($request_uri ~* ^/$){
        rewrite ^(.*)$ /index.php?s=/Home/$source_device/index.html last;
        break;
      }
      #電腦首頁
      if ($request_uri ~* ^/Home/index/index.html$) {
        rewrite ^/Home/index/index.html$ /web/ permanent;
        break;
      }
      #電腦首頁分頁
      if ($request_uri ~* ^/Home/index/index/page/(\d*).html$) {
        rewrite ^/Home/index/index/page/(\d*).html$ /web/pages/$1/ permanent;
        break;
      }
      #電腦首頁分類首頁
      if ($request_uri ~* ^/Home/index/index/cate/(\d*).html$) {
        rewrite ^/Home/index/index/cate/(\d*).html$ /web/cates/$1/ permanent;
        break;
      }
      #電腦首頁分類分頁
      if ($request_uri ~* ^/Home/index/index/cate/(\d*)/page/(\d*).html$) {
        rewrite ^/Home/index/index/cate/(\d*)/page/(\d*).html$ /web/cates/$1/pages/$2/ permanent;
        break;
      }
      #電腦首頁搜索
      if ($request_uri ~* ^/Home/index/index.html(.*)) {
        rewrite ^/Home/index/index.html(.*) /web/search?$query_string permanent;
        break;
      }
      #電腦書籍頁面
      if ($request_uri ~* ^/Home/index/books/book/(\d*).html$) {
        rewrite ^/Home/index/books/book/(\d*).html$ /web/books/$1/ permanent;
        break;
      }
      #電腦章節(jié)頁面
      if ($request_uri ~* ^/Home/index/contents/books/(\d*)/chapters/(\d*).html$) {
        rewrite ^/Home/index/contents/books/(\d*)/chapters/(\d*).html$ /web/books/$1/chapters/$2/ permanent;
        break;
      }
      #手機首頁
      if ($request_uri ~* ^/Home/phone/index.html$) {
        rewrite ^/Home/phone/index.html$ /phone/ last;
        break;
      }
      #手機首頁分頁
      if ($request_uri ~* ^/Home/phone/index/page/(\d*)(.*)$) {
        rewrite ^/Home/phone/index/page/(\d*).html /phone/pages/$1/ permanent;
        break;
      }
      #手機首頁分類首頁
      if ($request_uri ~* ^/Home/phone/index/cate/(\d*).html$) {
        rewrite ^/Home/phone/index/cate/(\d*).html$ /phone/cates/$1/ permanent;
        break;
      }
      #手機首頁分類分頁
      if ($request_uri ~* ^/Home/phone/index/cate/(\d*)/page/(\d*).html$) {
        rewrite ^/Home/phone/index/cate/(\d*)/page/(\d*).html$ /phone/cates/$1/pages/$2/ permanent;
        break;
      }
      #手機首頁搜索
      if ($request_uri ~* ^/Home/phone/index.html?(.*)) {
        rewrite ^/Home/phone/index.html(.*) /phone/index.html$1 permanent;
        break;
      }
      #手機書籍頁面
      if ($request_uri ~* ^/home/phone/books/book/(\d*).html$) {
        rewrite ^/home/phone/books/book/(\d*).html$ /phone/books/$1/ permanent;
        break;
      }
      #手機章節(jié)頁面
      if ($request_uri ~* ^/home/phone/contents/books/(\d*)/chapters/(\d*).html$) {
        rewrite ^/home/phone/contents/books/(\d*)/chapters/(\d*).html$ /phone/books/$1/chapters/$2/ permanent;
        break;
      }
      
      if ($request_uri ~* ^/Home/book/(.*)$) {
        rewrite ^(.*)$ /index.php?s=$1 last;
        break;
      }

      if (!-e $request_filename) {
        return 404;
      }
    }

電腦瀏覽器端

    location /web {
      root html;
      index index.html index.htm;
      #如果設備為手機或ipad
      if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        rewrite ^/web(.*) /phone$1 permanent;
      }
        #電腦首頁搜索
        if ($request_uri ~ ^/web/search(.*)$) {
          rewrite ^(.*) /index.php?s=/Home/index/index.html last;
          break;
        }
        #電腦首頁
        set $index false;
        if ($request_uri ~* ^/web$) {
          set $index true;
        }
        if ($request_uri ~* ^/web/$) {
          set $index true;
        }
        if ($index = true){
          rewrite ^/web(.*) /index.php?s=/Home/index/index.html last;
          break;
        }
        #電腦首頁分頁
        set $index_page false;
        if ($request_uri ~* ^/web/pages/(\d*)$) {
          set $index_page true;
        }
        if ($request_uri ~* ^/web/pages/(\d*)/$) {
          set $index_page true;
        }
        if ($index_page = true){
          rewrite ^/web/pages/(\d*)(.*) /index.php?s=/Home/index/index/page/$1.html last;
          break;
        }
        #電腦分類首頁
        set $cate false;
        if ($request_uri ~* ^/web/cates/(\d*)$) {
          set $cate true;
        }
        if ($request_uri ~* ^/web/cates/(\d*)/$) {
          set $cate true;
        }
        if ($cate = true){
          rewrite ^/web/cates/(\d*)(.*) /index.php?s=/Home/index/index/cate/$1.html last;
          break;
        }
        #電腦分類分頁
        set $cate_page false;
        if ($request_uri ~* ^/web/cates/(\d*)/pages/(\d*)$) {
          set $cate_page true;
        }
        if ($request_uri ~* ^/web/cates/(\d*)/pages/(\d*)/$) {
          set $cate_page true;
        }
        if ($cate_page = true){
          rewrite ^/web/cates/(\d*)/pages/(\d*)(.*) /index.php?s=/Home/index/index/cate/$1/page/$2.html last;
          break;
        }
        
        #電腦書籍頁面
        set $book false;
        if ($request_uri ~* ^/web/books/(\d*)$) {
          set $book true;
        }
        if ($request_uri ~* ^/web/books/(\d*)/$) {
          set $book true;
        }
        if ($book = true){
          rewrite ^/web/books/(\d*)(.*) /index.php?s=/Home/index/books/book/$1.html last;
          break;
        }
        #電腦章節(jié)頁面
        set $chapter false;
        if ($request_uri ~* ^/web/books/(\d*)/chapters/(.*)$) {
          set $chapter true;
        }
        if ($request_uri ~* ^/web/books/(\d*)/chapters/(.*)/$) {
          set $chapter true;
        }
        if ($chapter = true){
          rewrite ^/web/books/(\d*)/chapters/(.*)/ /index.php?s=/Home/index/contents/books/$1/chapters/$2.html last;
          break;
        }

        if (!-e $request_filename) {
          return 404;
        }
    }

手機和平板端

    location /phone {
      root html;
      index index.html index.htm;
      #如果設備不是手機或ipad
      if ($http_user_agent !~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        rewrite ^/phone(.*) /web$1 permanent;
      }
        #電腦首頁搜索
        if ($request_uri ~ ^/phone/search(.*)$) {
          rewrite ^(.*) /index.php?s=/Home/phone/index.html last;
          break;
        }
        #手機首頁
        set $index false;
        if ($request_uri ~* ^/phone$) {
          set $index true;
        }
        if ($request_uri ~* ^/phone/$) {
          set $index true;
        }
        if ($index = true){
          rewrite ^/phone(.*) /index.php?s=/Home/phone/index.html last;
          break;
        }
        #手機首頁分頁
        set $index_page false;
        if ($request_uri ~* ^/phone/pages/(\d*)$) {
          set $index_page true;
        }
        if ($request_uri ~* ^/phone/pages/(\d*)/$) {
          set $index_page true;
        }
        if ($index_page = true){
          rewrite ^/phone/pages/(\d*)(.*) /index.php?s=/Home/phone/index/page/$1.html last;
          break;
        }
        #手機分類首頁
        set $cate false;
        if ($request_uri ~* ^/phone/cates/(\d*)$) {
          set $cate true;
        }
        if ($request_uri ~* ^/phone/cates/(\d*)/$) {
          set $cate true;
        }
        if ($cate = true){
          rewrite ^/phone/cates/(\d*) /index.php?s=/Home/phone/index/cate/$1.html last;
          break;
        }
        #手機分類分頁
        set $cate_page false;
        if ($request_uri ~* ^/phone/cates/(\d*)/pages/(\d*)$) {
          set $cate_page true;
        }
        if ($request_uri ~* ^/phone/cates/(\d*)/pages/(\d*)/$) {
          set $cate_page true;
        }
        if ($cate_page = true){
          rewrite ^/phone/cates/(\d*)/pages/(\d*)(.*) /index.php?s=/Home/phone/index/cate/$1/page/$2.html last;
          break;
        }
        #手機書籍頁面
        set $book false;
        if ($request_uri ~* ^/phone/books/(\d*)$) {
          set $book true;
        }
        if ($request_uri ~* ^/phone/books/(\d*)/$) {
          set $book true;
        }
        if ($book = true){
          rewrite ^/phone/books/(\d*)(.*) /index.php?s=/Home/phone/books/book/$1.html last;
          break;
        }
        #手機書籍分頁頁面
        set $book false;
        if ($request_uri ~* ^/phone/books/(\d*)/pages/(\d*)$) {
          set $book true;
        }
        if ($request_uri ~* ^/phone/books/(\d*)/pages/(\d*)/$) {
          set $book true;
        }
        if ($book = true){
          rewrite ^/phone/books/(\d*)/pages/(\d*) /index.php?s=/Home/phone/books/book/$1/page/$2.html last;
          break;
        }
        #手機章節(jié)頁面
        set $chapter false;
        if ($request_uri ~* ^/phone/books/(\d*)/chapters/(.*)$) {
          set $chapter true;
        }
        if ($request_uri ~* ^/phone/books/(\d*)/chapters/(.*)/$) {
          set $chapter true;
        }
        if ($chapter = true){
          rewrite ^/phone/books/(\d*)/chapters/(.*)/ /index.php?s=/Home/phone/contents/books/$1/chapters/$2.html last;
          break;
        }

        if (!-e $request_filename) {
          return 404;
        }
    }
    location ~ .xml(.*) {
      root html/ttt/;
    }
 
    location ~ .txt(.*) {
      root html/ttt/;
    }
    location ~ .gif(.*) {
      root html/ttt/;
    }
    location ~ .jpg(.*) {
      root html/ttt/;
    }
    location ~ .css(.*) {
      root html/ttt/;
    }
    location ~ .js$ {
      root html/ttt/;
    }
    location ~ .php$ {
      root html/ttt;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_buffers 8 256k;
      fastcgi_connect_timeout 300s;
      fastcgi_send_timeout 300s;
      fastcgi_read_timeout 300s;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }
  }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

標簽:玉樹 張家界 洛陽 北京 滄州 永州 松原 廊坊

巨人網絡通訊聲明:本文標題《nginx配置偽靜態(tài)和適配客戶端的方法步驟》,本文關鍵詞  nginx,配置,偽,靜態(tài),和,適配,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《nginx配置偽靜態(tài)和適配客戶端的方法步驟》相關的同類信息!
  • 本頁收集關于nginx配置偽靜態(tài)和適配客戶端的方法步驟的相關信息資訊供網民參考!
  • 推薦文章