How to configure pseudo-static and adapt client in nginx
后端用的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; } }
电脑浏览器端
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; } #电脑章节页面 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; } #手机章节页面 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 detailed content of How to configure pseudo-static and adapt client in nginx. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to fix Nginx 403 Forbidden error? Check file or directory permissions; 2. Check .htaccess file; 3. Check Nginx configuration file; 4. Restart Nginx. Other possible causes include firewall rules, SELinux settings, or application issues.

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

Answer to the question: 304 Not Modified error indicates that the browser has cached the latest resource version of the client request. Solution: 1. Clear the browser cache; 2. Disable the browser cache; 3. Configure Nginx to allow client cache; 4. Check file permissions; 5. Check file hash; 6. Disable CDN or reverse proxy cache; 7. Restart Nginx.
