至尊技术网 - Nginx https://www.zzwws.cn/tag/Nginx/ Nginx负载均衡 https://www.zzwws.cn/archives/6393/ 2023-04-12T10:44:00+08:00 1、轮询轮询是upstream模块负载均衡默认的策略,每个请求会按时间顺序逐个被分配到不同的后端服务器。轮询不需要额外的配置。# 代理服务器 # 设置服务器组 upstream backend { server 111.173.115.2:80; server 111.173.115.3:80; server 111.173.115.4:80; } server { listen 80; server_name 111.173.115.1; location / { # backend 就是服务器组的名称 proxy_pass http://backend/; } } 2、weight加权(加权轮询)weight=number:用来设置服务器的权重,默认为1,权重数字越大,被分配到请求的几率越大。该权重值主要是针对实际工作环境中不同的后端服务器硬件配置进行调整的,所有此策略比较适合服务器的硬件配置差别比较大的情况。# 代理服务器 # 设置服务器组 upstream backend { server 111.173.115.2:80 weight=10; server 111.173.115.3:80 weight=8; server 111.173.115.4:80 weight=6; } server { listen 80; server_name 111.173.115.1; location / { # backend 就是服务器组的名称 proxy_pass http://backend/; } } 3、ip_hash当对后端的多台动态应用服务器做负载均衡时,ip_hash指令能够将某个客户端IP的请求通过哈希算法定位到同一台后端服务器上。这样,当来自某一个IP的用户在后端Web服务器A上登录后,再访问该站点的其他URL,能保证其访问的还是后端web服务器A。注意:使用ip_hash指令无法保证后端服务器的负载均衡,可能导致有些后端服务器接收到的请求多,有些后端服务器接受的请求少,而且设置后端服务器权重等方法将不起作用。# 代理服务器 # 设置服务器组 upstream backend { ip_hash; server 111.173.115.2:80; server 111.173.115.3:80; server 111.173.115.4:80; } server { listen 80; server_name 111.173.115.1; location / { # backend 就是服务器组的名称 proxy_pass http://backend/; } } 4、least_connleast_conn:最少连接,把请求转发给连接数较少的后端服务器。轮询算法是把请求平均地转发给各个后端,使它们的负载大致相同;但是,有些请求占用的时间很长,会导致其所在的后端负载较高。这种情况下,least_conn这种方式就可以达到更好的负载均衡效果。# 代理服务器 # 设置服务器组 upstream backend { least_conn; server 111.173.115.2:80; server 111.173.115.3:80; server 111.173.115.4:80; } server { listen 80; server_name 111.173.115.1; location / { # backend 就是服务器组的名称 proxy_pass http://backend/; } } 5、url_hash按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,要配合缓存命中来使用。同一个资源多次请求,可能会到达不同的服务器上,导致不必要的多次下载,缓存命中率不高,以及一些资源时间的浪费。而使用url_hash,可以使得同一个url(也就是同一个资源请求)会到达同一台服务器,一旦缓存住了资源,再次收到请求,就可以从缓存中读取。# 代理服务器 # 设置服务器组 upstream backend { hash $request_uri; server 111.173.115.2:80; server 111.173.115.3:80; server 111.173.115.4:80; } server { listen 80; server_name 111.173.115.1; location / { # backend 就是服务器组的名称 proxy_pass http://backend/; } } 6、fairfair采用的不是内建负载均衡使用的均衡算法,而是可以根据页面大小、加载时间长短智能地进行负载均衡。那么如何使用第三方模块的fair负载均衡策略?# 代理服务器 # 设置服务器组 upstream backend { fair; server 111.173.115.2:80; server 111.173.115.3:80; server 111.173.115.4:80; } server { listen 80; server_name 111.173.115.1; location / { # backend 就是服务器组的名称 proxy_pass http://backend/; } } 但是如果直接使用会报错,因为fair属于第三方模块实现的负载均衡。需要添加nginx-upstream-fair,如何添加对应的模块:1.下载nginx-upstream-fair模块。https://github.com/gnosek/nginx-upstream-fair2.将下载的文件上传到服务器并进行解压缩。unzip nginx-upstream-fair-master.zip3.重命名资源。mv nginx-upstream-fair-master fair4.使用./configure命令将资源添加到Nginx模块中。./configure --add-module=/root/fair5.编译。make-编译可能会出现如下错误: nginx_http_upstream_srv_conf_t结构中缺少default_port -解决方案 在Nginx的源码中src/http/nginx_http_upstream.h,找到ngx_http_upstream_srv_conf_s,在模块中添加default_port属性:in_port_t default_port 然后再进行make。6.更新Nginx。1、将sbin目录下的nginx进行备份mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginxold 2、将安装目录下的objs中的nginx拷贝到sbin目录cd objscp nginx /usr/local/nginx/sbin 3、更新cd ../make upgrade7.编译测试使用Nginx。 Apache与NGINX下Access-Control-Allow-Origin * 设置 https://www.zzwws.cn/archives/2445/ 2019-12-26T13:52:00+08:00 介绍网站一般在需要共享资源给其他网站时(跨域传递数据),才会设置access-control-allow-origin HTTP头设置Access-Control-Allow-Origin,可以解决多域名跨域问题Access-Control-Allow-Origin * 等所有网站都可以跨域访问Access-Control-Allow-Origin zzwws.cn 允许zzwws.cn跨域访问Apache<IfModule mod_headers.c> Header set Access-Control-Allow-Origin: "*" Header set Access-Control-Allow-Methods: "GET,POST,PUT,DELETE,OPTIONS" Header set Access-Control-Allow-Headers: "Content-Type" </IfModule> 添加到httpd.conf最下面NGINXadd_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'PUT,POST,GET,DELETE,OPTIONS'; add_header 'Access-Control-Allow-Headers' 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With'; 或location / { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"; add_header Access-Control-Allow-Methods "GET, POST, OPTIONS"; } 将代码添加到NGINXHTML<meta http-equiv="Access-Control-Allow-Origin" content="*" /> Javaresponse.setHeader("Access-Control-Allow-Origin", "*"); .netResponse.AddHeader("Access-Control-Allow-Origin", "*"); Apache及Nginx常用伪静态规则 https://www.zzwws.cn/archives/2443/ 2019-12-26T13:47:00+08:00 Apache伪静态规则EmpireCMSRewriteEngine On RewriteBase / RewriteRule ^([0-9]+).([0-9]+)/$ e/action/ShowInfo.php?classid=$1&id=$2 [L] RewriteRule ^([0-9]+).([0-9]+)$ $1.$2/ [L,R=301] RewriteRule ^([0-9]+)/$ e/action/ListInfo/?classid=$1 [L] RewriteRule ^([0-9]+)$ $1/ [L,R=301] RewriteRule ^list([0-9]+).([0-9]+)/$ e/action/ListInfo/index.php?page=$1&classid=$2 [L] RewriteRule ^list([0-9]+).([0-9]+)$ list$1.$2/ [L,R=301] RewriteRule^archive([0-9]+).([0-9]+)-([0-9]+)-([0-9]+)/$e/action/ListInfo.php?classid=$1&mid=1&tempid=9&starttime=$2-$3-$4&endtime=$2-$3-$4 [L] RewriteRule^archive([0-9]+).([0-9]+)-([0-9]+)-([0-9]+)$^archive([0-9]+).([0-9]+)-([0-9]+)-([0-9]+)/ [L,R=301] dedecmsRewriteEngine On RewriteBase / RewriteRule ^(.*)/question-id-([0-9]+)\.html$ $1/question\.php\?id=$2 RewriteRule ^(.*)/browser-tid-([0-9]+)\.html$ $1/browser\.php\?tid=$2 RewriteRule ^(.*)/browser-tid2-([0-9]+)\.html$ $1/browser\.php\?tid2=$2 RewriteRule ^(.*)/browser-lm-([0-9]+)\.html$ $1/browser\.php\?lm=$2 RewriteRule ^(.*)/browser-tid-([0-9]+)-lm-([0-9]+)\.html$ $1/browser\.php\?tid=$2&lm=$3 RewriteRule ^(.*)/browser-tid2-([0-9]+)-lm-([0-9]+)\.html$ $1/browser\.php\?tid2=$2&lm=$3 RewriteRule ^(.*)index\.html$ $1/index.php RewriteRule ^(.*)list-([0-9]+)\.html$ $1/plus/list.php?tid=$2 RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/plus/list.php?typeid=$2&PageNo=$3 RewriteRule ^(.*)view-([0-9]+).html$ $1/plus/view.php?aid=$2 RewriteRule ^(.*)view-([0-9]+)-([0-9]+).html$ $1/plus/view.php?aid=$2&pageno=$3 discuzxRewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^([a-z]+)-(.+)\.html$ $1.php?rewrite=$2&%1 discuzx2RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1 discuzx3RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1 ecshopRewriteEngine On RewriteBase / # direct one-word access RewriteRule ^index\.html$ index\.php [L] RewriteRule ^category$ index\.php [L] # access any object by its numeric identifier RewriteRule ^feed-c([0-9]+)\.xml$ feed\.php\?cat=$1 [L] RewriteRule ^feed-b([0-9]+)\.xml$ feed\.php\?brand=$1 [L] RewriteRule ^feed\.xml$ feed\.php [L] RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 [QSA,L] RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 [QSA,L] RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3&sort=$4&order=$5 [QSA,L] RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3 [QSA,L] RewriteRule ^category-([0-9]+)-b([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2 [QSA,L] RewriteRule ^category-([0-9]+)(.*)\.html$ category\.php\?id=$1 [QSA,L] RewriteRule ^goods-([0-9]+)(.*)\.html$ goods\.php\?id=$1 [QSA,L] RewriteRule ^article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2&sort=$3&order=$4 [QSA,L] RewriteRule ^article_cat-([0-9]+)-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2 [QSA,L] RewriteRule ^article_cat-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1 [QSA,L] RewriteRule ^article-([0-9]+)(.*)\.html$ article\.php\?id=$1 [QSA,L] RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html brand\.php\?id=$1&cat=$2&page=$3&sort=$4&order=$5 [QSA,L] RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2&page=$3 [QSA,L] RewriteRule ^brand-([0-9]+)-c([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2 [QSA,L] RewriteRule ^brand-([0-9]+)(.*)\.html brand\.php\?id=$1 [QSA,L] RewriteRule ^tag-(.*)\.html search\.php\?keywords=$1 [QSA,L] RewriteRule ^snatch-([0-9]+)\.html$ snatch\.php\?id=$1 [QSA,L] RewriteRule ^group_buy-([0-9]+)\.html$ group_buy\.php\?act=view&id=$1 [QSA,L] RewriteRule ^auction-([0-9]+)\.html$ auction\.php\?act=view&id=$1 [QSA,L] mvc<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule> phpcmsRewriteEngine On RewriteBase / RewriteRule ^(.*)content-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=$3&page=$4 RewriteRule ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=$3&page=$4 RewriteRule ^(.*)list-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=lists&catid=$2&page=$3 phpwindRewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule !.(js|ico|gif|jpe?g|bmp|png|css)$ /index.php [NC,L] thinkphp<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L] </IfModule> wordpress<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> zblog<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> typecho<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] </IfModule> Nginx伪静态规则EmpireCMSrewrite ^([^\.]*)/listinfo-(.+?)-(.+?)\.html$ $1/e/action/ListInfo/index.php?classid=$2&page=$3 last; rewrite ^([^\.]*)/showinfo-(.+?)-(.+?)-(.+?)\.html$ $1/e/action/ShowInfo.php?classid=$2&id=$3&page=$4 last; rewrite ^([^\.]*)/infotype-(.+?)-(.+?)\.html$ $1/e/action/InfoType/index.php?ttid=$2&page=$3 last; rewrite ^([^\.]*)/tags-(.+?)-(.+?)\.html$ $1/e/tags/index.php?tagname=$2&page=$3 last; rewrite ^([^\.]*)/comment-(.+?)-(.+?)-(.+?)-(.+?)-(.+?)-(.+?)\.html$ $1/e/pl/index\.php\?doaction=$2&classid=$3&id=$4&page=$5&myorder=$6&tempid=$7 last; if (!-e $request_filename) { return 404; } dabrlocation / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; } } dbshoplocation /{ try_files $uri $uri/ /index.php$is_args$args; } location ~ \.htaccess{ deny all; } dedecmsrewrite "^/list-([0-9]+)\.html$" /plus/list.php?tid=$1 last; rewrite "^/list-([0-9]+)-([0-9]+)-([0-9]+)\.html$" /plus/list.php?tid=$1&totalresult=$2&PageNo=$3 last; rewrite "^/view-([0-9]+)-1\.html$" /plus/view.php?arcID=$1 last; rewrite "^/view-([0-9]+)-([0-9]+)\.html$" /plus/view.php?aid=$1&pageno=$2 last; rewrite "^/plus/list-([0-9]+)\.html$" /plus/list.php?tid=$1 last; rewrite "^/plus/list-([0-9]+)-([0-9]+)-([0-9]+)\.html$" /plus/list.php?tid=$1&totalresult=$2&PageNo=$3 last; rewrite "^/plus/view-([0-9]+)-1\.html$" /plus/view.php?arcID=$1 last; rewrite "^/plus/view-([0-9]+)-([0-9]+)\.html$" /plus/view.php?aid=$1&pageno=$2 last; rewrite "^/tags.html$" /tags.php last; rewrite "^/tag-([0-9]+)-([0-9]+)\.html$" /tags.php?/$1/$2/ last; discuzlocation / { rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last; rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last; rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last; rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last; rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last; } discuzxrewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last; rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last; rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last; rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last; rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last; rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last; rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last; rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last; if (!-e $request_filename) { return 404; } discuzx2location /bbs/ { rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last; rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last; rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last; rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last; rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last; rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last; rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last; rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last; if (!-e $request_filename) { return 404; } } discuzx3location / { rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last; rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last; rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last; rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last; rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last; rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last; rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last; rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last; if (!-e $request_filename) { return 404; } } drupalif (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; } ecshop if (!-e $request_filename) { rewrite "^/index\.html" /index.php last; rewrite "^/category$" /index.php last; rewrite "^/feed-c([0-9]+)\.xml$" /feed.php?cat=$1 last; rewrite "^/feed-b([0-9]+)\.xml$" /feed.php?brand=$1 last; rewrite "^/feed\.xml$" /feed.php last; rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last; rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last; rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last; rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3 last; rewrite "^/category-([0-9]+)-b([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2 last; rewrite "^/category-([0-9]+)(.*)\.html$" /category.php?id=$1 last; rewrite "^/goods-([0-9]+)(.*)\.html" /goods.php?id=$1 last; rewrite "^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last; rewrite "^/article_cat-([0-9]+)-([0-9]+)(.*)\.html$" /article_cat.php?id=$1&page=$2 last; rewrite "^/article_cat-([0-9]+)(.*)\.html$" /article_cat.php?id=$1 last; rewrite "^/article-([0-9]+)(.*)\.html$" /article.php?id=$1 last; rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html" /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last; rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2&page=$3 last; rewrite "^/brand-([0-9]+)-c([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2 last; rewrite "^/brand-([0-9]+)(.*)\.html" /brand.php?id=$1 last; rewrite "^/tag-(.*)\.html" /search.php?keywords=$1 last; rewrite "^/snatch-([0-9]+)\.html$" /snatch.php?id=$1 last; rewrite "^/group_buy-([0-9]+)\.html$" /group_buy.php?act=view&id=$1 last; rewrite "^/auction-([0-9]+)\.html$" /auction.php?act=view&id=$1 last; rewrite "^/exchange-id([0-9]+)(.*)\.html$" /exchange.php?id=$1&act=view last; rewrite "^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last; rewrite ^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last; rewrite "^/exchange-([0-9]+)-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2 last; rewrite "^/exchange-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1 last; } emloglocation / { index index.php index.html; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php last; } } laravel5 location / { try_files $uri $uri/ /index.php$is_args$query_string; } maccmsrewrite ^/vod-(.*)$ /index.php?m=vod-$1 break; rewrite ^/art-(.*)$ /index.php?m=art-$1 break; rewrite ^/gbook-(.*)$ /index.php?m=gbook-$1 break; rewrite ^/label-(.*)$ /index.php?m=label-$1 break; rewrite ^/map-(.*)$ /index.php?m=map-$1 break; mvclocation /{ if (!-e $request_filename) { rewrite ^(.*)$ /index.php/$1 last; break; } } niushoplocation / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } phpcmslocation / { ###以下为PHPCMS 伪静态化rewrite法则 rewrite ^(.*)show-([0-9]+)-([0-9]+)\.html$ $1/show.php?itemid=$2&page=$3; rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/list.php?catid=$2&page=$3; rewrite ^(.*)show-([0-9]+)\.html$ $1/show.php?specialid=$2; ####以下为PHPWind 伪静态化rewrite法则 rewrite ^(.*)-htm-(.*)$ $1.php?$2 last; rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last; } phpwindlocation / { rewrite ^(.*)-htm-(.*)$ $1.php?$2 last; rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last; } sabloglocation / { rewrite "^/date/([0-9]{6})/?([0-9]+)?/?$" /index.php?action=article&setdate=$1&page=$2 last; rewrite ^/page/([0-9]+)?/?$ /index.php?action=article&page=$1 last; rewrite ^/category/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&cid=$1&page=$2 last; rewrite ^/category/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&curl=$1&page=$2 last; rewrite ^/(archives|search|article|links)/?$ /index.php?action=$1 last; rewrite ^/(comments|tagslist|trackbacks|article)/?([0-9]+)?/?$ /index.php?action=$1&page=$2 last; rewrite ^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&item=$1&page=$2 last; rewrite ^/archives/([0-9]+)/?([0-9]+)?/?$ /index.php?action=show&id=$1&page=$2 last; rewrite ^/rss/([0-9]+)?/?$ /rss.php?cid=$1 last; rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last; rewrite ^/uid/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&uid=$1&page=$2 last; rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last; rewrite sitemap.xml sitemap.php last; rewrite ^(.*)/([0-9a-zA-Z\-\_]+)/?([0-9]+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last; } seacmslocation / { rewrite ^/frim/index(.+?)\.html$ /list/index.php?$1 last; rewrite ^/movie/index(.+?)\.html$ /detail/index.php?$1 last; rewrite ^/play/([0-9]+)-([0-9]+)-([0-9]+)\.html$ /video/index.php?$1-$2-$3 last; rewrite ^/topic/index(.+?)\.html$ /topic/index.php?$1 last; rewrite ^/topiclist/index(.+?).html$ /topiclist/index.php?$1 last; rewrite ^/index\.html$ index.php permanent; rewrite ^/news\.html$ news/ permanent; rewrite ^/part/index(.+?)\.html$ /articlelist/index.php?$1 last; rewrite ^/article/index(.+?)\.html$ /article/index.php?$1 last; } shopexlocation / { if (!-e $request_filename) { rewrite ^/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ /index.php?$1 last; } } thinkphplocation / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } typechoif (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } typecho2location /typecho/ { if (!-e $request_filename) { rewrite ^(.*)$ /typecho/index.php$1 last; } } wordpresslocation / { try_files $uri $uri/ /index.php?$args; } rewrite /wp-admin$ $scheme://$host$uri/ permanent; wp2rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last; if (!-e $request_filename){ rewrite ^.+?(/wp-.*) $1 last; rewrite ^.+?(/.*\.php)$ $1 last; rewrite ^ /index.php last; } zblogif (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; }