首页 > 网站 > Nginx > 正文

nginx配置伪静态和适配客户端的方法步骤

2024-08-30 12:24:23
字体:
来源:转载
供稿:网友

后端用的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;      }      #电脑章节页面      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;      }      #手机章节页面      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;      }    }            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表