[תÔØ]nginx rewrite¹æÔò(2)
Îļþ·´µÁÁ´²¢ÉèÖùýÆÚʱ¼ä
ÕâÀïµÄreturn 412 Ϊ×Ô¶¨ÒåµÄhttp״̬Â룬ĬÈÏΪ403£¬·½±ãÕÒ³öÕýÈ·µÄµÁÁ´µÄÇëÇó
¡°rewrite ^/ http://leech.c1gstudio.com/leech.gif;¡±ÏÔʾһÕÅ·ÀµÁÁ´Í¼Æ¬
¡°access_log off;¡±²»¼Ç¼·ÃÎÊÈÕÖ¾£¬¼õÇáѹÁ¦
¡°expires 3d¡±ËùÓÐÎļþ3ÌìµÄä¯ÀÀÆ÷»º´æ
- location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
- valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194;
- if ($invalid_referer) {
- rewrite ^/ http://leech.c1gstudio.com/leech.gif;
- return 412;
- break;
- }
- access_log off;
- root /opt/lampp/htdocs/web;
- expires 3d;
- break;
- }
Ö»³äÐí¹Ì¶¨ip·ÃÎÊÍøÕ¾£¬²¢¼ÓÉÏÃÜÂë
- root /opt/htdocs/www;
- allow 208.97.167.194;
- allow 222.33.1.2;
- allow 231.152.49.4;
- deny all;
- auth_basic ¡°C1G_ADMIN¡±;
- auth_basic_user_file htpasswd;
½«¶à¼¶Ä¿Â¼ÏµÄÎļþת³ÉÒ»¸öÎļþ£¬ÔöÇ¿seoЧ¹û
/job-123-456-789.html Ö¸Ïò/job/123/456/789.html
- rewrite ^/job-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /job/$1/$2/jobshow_$3.html last;
½«¸ùĿ¼ÏÂij¸öÎļþ¼ÐÖ¸Ïò2¼¶Ä¿Â¼
Èç/shanghaijob/ Ö¸Ïò /area/shanghai/
Èç¹ûÄ㽫last¸Ä³Épermanent£¬ÄÇôä¯ÀÀÆ÷µØÖ·À¸ÏÔÊÇ/location/shanghai/
- rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
ÉÏÃæÀý×ÓÓиöÎÊÌâÊÇ·ÃÎÊ/shanghai ʱ½«²»»áÆ¥Åä
- rewrite ^/([0-9a-z]+)job$ /area/$1/ last;
- rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
ÕâÑù/shanghai Ò²¿ÉÒÔ·ÃÎÊÁË£¬µ«Ò³ÃæÖеÄÏà¶ÔÁ´½ÓÎÞ·¨Ê¹Óã¬
Èç./list_1.htmlÕæʵµØÖ·ÊÇ/area/shanghia/list_1.html»á±ä³É/list_1.html,µ¼ÖÁÎÞ·¨·ÃÎÊ¡£
ÄÇÎÒ¼ÓÉÏ×Ô¶¯ÌøתҲÊDz»Ðп©
(-d $request_filename)ËüÓиöÌõ¼þÊDZØÐèΪÕæʵĿ¼£¬¶øÎÒµÄrewrite²»Êǵģ¬ËùÒÔûÓÐЧ¹û
- if (-d $request_filename){
- rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
- }
ÖªµÀÔÒòºó¾ÍºÃ°ìÁË£¬ÈÃÎÒÊÖ¶¯Ìøת°É
- rewrite ^/([0-9a-z]+)job$ /$1job/ permanent;
- rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;
ÎļþºÍĿ¼²»´æÔÚµÄʱºòÖض¨Ïò£º
- if (!-e $request_filename) {
- proxy_pass http://127.0.0.1;
- }
ÓòÃûÌøת
- server
- {
- listen 80;
- server_name jump.c1gstudio.com;
- index index.html index.htm index.php;
- root /opt/lampp/htdocs/www;
- rewrite ^/ http://www.c1gstudio.com/;
- access_log off;
- }
¶àÓòÃûתÏò
- server_name www.c1gstudio.com www.c1gstudio.net;
- index index.html index.htm index.php;
- root /opt/lampp/htdocs;
- if ($host ~ ¡°c1gstudio\.net¡±) {
- rewrite ^(.*) http://www.c1gstudio.com$1 permanent;
- }
Èý¼¶ÓòÃûÌøת
- if ($http_host ~* ¡°^(.*)\.i\.c1gstudio\.com$¡±) {
- rewrite ^(.*) http://top.yingjiesheng.com$1;
- break;
- }
ÓòÃû¾µÏò
- server
- {
- listen 80;
- server_name mirror.c1gstudio.com;
- index index.html index.htm index.php;
- root /opt/lampp/htdocs/www;
- rewrite ^/(.*) http://www.c1gstudio.com/$1 last;
- access_log off;
- }
ij¸ö×ÓĿ¼×÷¾µÏò
- location ^~ /zhaopinhui {
- rewrite ^.+ http://zph.c1gstudio.com/ last;
- break;
- }
discuz ucenter home (uchome) rewrite
- rewrite ^/(space|network)-(.+)\.html$ /$1.php?rewrite=$2 last;
- rewrite ^/(space|network)\.html$ /$1.php last;
- rewrite ^/([0-9]+)$ /space.php?uid=$1 last;
discuz 7 rewrite
- rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
- rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
- rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\=$4&page=$3 last;
- rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
- rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;
- rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last;
¸ødiscuzij°æ¿éµ¥¶ÀÅäÖÃÓòÃû
- server_name bbs.c1gstudio.com news.c1gstudio.com;
- location = / {
- if ($http_host ~ news\.c1gstudio.com$) {
- rewrite ^.+ http://news.c1gstudio.com/forum-831-1.html last;
- break;
- }
- }
discuz ucenter Í·Ïñ rewrite ÓÅ»¯
- location ^~ /ucenter {
- location ~ .*\.php?$
- {
- #fastcgi_pass unix:/tmp/php-cgi.sock;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fcgi.conf;
- }
- location /ucenter/data/avatar {
- log_not_found off;
- access_log off;
- location ~ /(.*)_big\.jpg$ {
- error_page 404 /ucenter/images/noavatar_big.gif;
- }
- location ~ /(.*)_middle\.jpg$ {
- error_page 404 /ucenter/images/noavatar_middle.gif;
- }
- location ~ /(.*)_small\.jpg$ {
- error_page 404 /ucenter/images/noavatar_small.gif;
- }
- expires 300;
- break;
- }
- }
jspace rewrite
- location ~ .*\.php?$
- {
- #fastcgi_pass unix:/tmp/php-cgi.sock;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fcgi.conf;
- }
- location ~* ^/index.php/
- {
- rewrite ^/index.php/(.*) /index.php?$1 break;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fcgi.conf;
- }
ÁíÍâÕâÀﻹÓÐÒ»¸ö¹¤¾ß¿ÉÒÔÖ±½Ó°Ñapache¹æÔòת»¯Îªnginx¹æÔò
http://www.anilcetin.com/convert-apache-htaccess-to-nginx/
²Î¿¼£º
http://wiki.nginx.org/NginxChsHttpRewriteModule
http://blog.csdn.net/cnbird2008/archive/2009/08/04/4409620.aspx
ÆÀÂÛ