How to configure pseudo-static and client-adaptive Nginx

How to configure pseudo-static and client-adaptive Nginx

The backend uses the thinkphp3.2.3 framework. If you are using other languages, please make appropriate changes.

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

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

Website root directory

    location / {
      root html;
      index index.html index.htm;
      #Set the access device set $source_device 'index';
      #Judge whether it is a mobile client or iPad
      if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        set $source_device 'phone';
      }
      #root directoryif ($request_uri ~* ^/$){
        rewrite ^(.*)$ /index.php?s=/Home/$source_device/index.html last;
        break;
      }
      #Computer homepageif ($request_uri ~* ^/Home/index/index.html$) {
        rewrite ^/Home/index/index.html$ /web/ permanent;
        break;
      }
      #Computer home page paging if ($request_uri ~* ^/Home/index/index/page/(\d*).html$) {
        rewrite ^/Home/index/index/page/(\d*).html$ /web/pages/$1/ permanent;
        break;
      }
      #Computer home page Category home page if ($request_uri ~* ^/Home/index/index/cate/(\d*).html$) {
        rewrite ^/Home/index/index/cate/(\d*).html$ /web/cates/$1/ permanent;
        break;
      }
      #Computer home page category paging 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;
      }
      #Computer home page search if ($request_uri ~* ^/Home/index/index.html(.*)) {
        rewrite ^/Home/index/index.html(.*) /web/search?$query_string permanent;
        break;
      }
      #Computer book page if ($request_uri ~* ^/Home/index/books/book/(\d*).html$) {
        rewrite ^/Home/index/books/book/(\d*).html$ /web/books/$1/ permanent;
        break;
      }
      #Computer chapter page 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;
      }
      #Mobile homepageif ($request_uri ~* ^/Home/phone/index.html$) {
        rewrite ^/Home/phone/index.html$ /phone/ last;
        break;
      }
      #Mobile home page paging if ($request_uri ~* ^/Home/phone/index/page/(\d*)(.*)$) {
        rewrite ^/Home/phone/index/page/(\d*).html /phone/pages/$1/ permanent;
        break;
      }
      #Mobile home page Category home page if ($request_uri ~* ^/Home/phone/index/cate/(\d*).html$) {
        rewrite ^/Home/phone/index/cate/(\d*).html$ /phone/cates/$1/ permanent;
        break;
      }
      #Mobile home page category paging 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;
      }
      #Mobile homepage searchif ($request_uri ~* ^/Home/phone/index.html?(.*)) {
        rewrite ^/Home/phone/index.html(.*) /phone/index.html$1 permanent;
        break;
      }
      #Mobile book pageif ($request_uri ~* ^/home/phone/books/book/(\d*).html$) {
        rewrite ^/home/phone/books/book/(\d*).html$ /phone/books/$1/ permanent;
        break;
      }
      #Mobile chapter pageif ($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;
      }
    }

Computer browser

    location /web {
      root html;
      index index.html index.htm;
      #If the device is a mobile phone or iPad
      if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        rewrite ^/web(.*) /phone$1 permanent;
      }
        #Computer homepage searchif ($request_uri ~ ^/web/search(.*)$) {
          rewrite ^(.*) /index.php?s=/Home/index/index.html last;
          break;
        }
        #Computer home page 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;
        }
        #Computer home page paging 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;
        }
        #Computer category homepage 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;
        }
        #Computer category paging 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;
        }
        
        #Computer book page 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;
        }
        #Computer chapter page 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;
        }
    }

Mobile and tablet

    location /phone {
      root html;
      index index.html index.htm;
      #If the device is not a mobile phone or iPad
      if ($http_user_agent !~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        rewrite ^/phone(.*) /web$1 permanent;
      }
        #Computer homepage searchif ($request_uri ~ ^/phone/search(.*)$) {
          rewrite ^(.*) /index.php?s=/Home/phone/index.html last;
          break;
        }
        #Mobile homepage 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;
        }
        #Mobile home page paging 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;
        }
        #Mobile phone category homepage 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;
        }
        #Mobile phone category paging 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;
        }
        #Mobile book page 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;
        }
        #Mobile book paging page 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;
        }
        #Mobile chapter page 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;
    }
  }

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Example of how to set WordPress pseudo-static in Nginx
  • How to configure Nginx pseudo-static in Yii2
  • Nginx pseudo-static configuration and common Rewrite pseudo-static rules collection
  • Pseudo-static rules of Nginx servers for some commonly used PHP CMS in China
  • nginx rewrite pseudo-static configuration parameters and usage examples
  • Detailed description of nginx rewrite pseudo-static configuration parameters
  • nginx pseudo-static rewrite rules

<<:  InnoDB type MySql restore table structure and data

>>:  jQuery implements percentage scoring progress bar

Recommend

SQL insert into statement writing method explanation

Method 1: INSERT INTO t1(field1,field2) VALUE(v00...

Let's talk in detail about how the NodeJS process exits

Table of contents Preface Active withdrawal Excep...

vue-router history mode server-side configuration process record

history route History mode refers to the mode of ...

Linux file and user management practice

1. Display the files or directories in the /etc d...

js to create a carousel effect

I think the carousel is a relatively important po...

In-depth analysis of the diff algorithm in React

Understanding of diff algorithm in React diff alg...

Web design experience: Make the navigation system thin

<br />When discussing with my friends, I men...

HTML marquee tag usage examples

This tag is not part of HTML3.2 and only supports ...

JavaScript CollectGarbage Function Example

First, let's look at an example of memory rel...

Solution to the problem of null column in NOT IN filling pit in MySQL

Some time ago, when I was working on a small func...

Detailed steps for installing, configuring and uninstalling QT5 in Ubuntu 14.04

1. I downloaded QT5.13 version before, but after ...

Understanding v-bind in vue

Table of contents 1. Analysis of key source code ...

Tomcat CentOS installation process diagram

Tomcat CentOS Installation This installation tuto...