配置nginx1.6.2要求訪問$uri如果1)如果存在文件/Vhost/$http_host/$uri,訪問的是該文件2)否則如果$uri不是以“/”結(jié)尾301跳轉(zhuǎn)到$uri/3)否則如果$uri以“/”結(jié)尾且存在/Cache/$http_host/$uri/index.html,訪問的是該文件4)否則指向/index.php(ThinkPHP框架)例子訪問http://www.a.com/robots.txt->/Vhost/www.a.com/robots.txt訪問http://a.com/robots.txt->301跳轉(zhuǎn)->http://www.a.com/robots.txt訪問http://www.c.com/sitemap.html->/Vhost/www.c.com/sitemap.html訪問http://www.d.com/game/->/Cache/www.d.com/game/index.html訪問http://www.d.com/news/1000011->301跳轉(zhuǎn)到->http://www.d.com/news/1000011/訪問http://www.d.com/news/1000011/->/index.php(當(dāng)該/Cache/www.d.com/news/1000011/index.html不存在的時候)訪問http://www.d.com/news/1000011/->/Cache/www.d.com/news/100011/index.html(當(dāng)該/Cache/www.d.com/news/1000011/index.html存在的時候)配置server{listen80;server_namewapwap.locm.wap.locwap.locm.xxx.comgame1.wap.locgame2.wap.locgame3.wap.loc;location/{rootd:/wap_dev;indexindex.htmlindex.htmindex.php;try_files$uri/Vhost/$http_host/$uri/Cache/$http_host/$uri/index.html/index.php?s=$uri&$args;location~\.php${try_files$uri=404;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}}#error_page404/404.html;#redirectservererrorpagestothestaticpage/50x.html#error_page500502503504/50x.html;location=/50x.html{roothtml;}location~/\.(ht|svn|git){denyall;}}問題已經(jīng)實現(xiàn)了上面的1、3、4,還有2未實現(xiàn)。上面第3)點打錯字了,是如下的。已經(jīng)修改了的,但是sg沒有變化3)否則如果$uri以“/”結(jié)尾且存在/Cache/$http_host/$uri/index.html,訪問的是該文件補(bǔ)充1)如何才可以不是以/結(jié)尾且不是以.xml結(jié)尾且不是以.html.htm結(jié)尾的才跳轉(zhuǎn)現(xiàn)在是不是以/結(jié)尾的跳轉(zhuǎn),導(dǎo)致.xml結(jié)尾.html結(jié)尾的也都跳轉(zhuǎn)自己寫了一段,但是失?。簉ewrite([^\/]|\.xml|\.html?)$$uri/permanent;
nginx重寫:如果$uri 不是文件不是目錄 跳轉(zhuǎn)到$uri/
Qyouu
2019-04-16 20:26:24