ºÆº£´úÂëÍø£¬ÖÂÁ¦ÓÚ×ö×îʵÓõĴúÂëÍø£¬Îª¸öÈËÕ¾³¤ÓëÆóÒµÍøÂçÌṩȫÃæµÄÕ¾³¤×ÊѶ¡¢ÍøÕ¾ÔËÓªµÈ×îÐÂ×îÈ«×îʵÓõĴúÂë³ÌÐò¡¢ÌṩÏÂÔØÔ´Â룬°ïÖú³ÌÐòԱѧºÃLinux¡¢PHP¡¢Nginx¡¢MySQL¡¢NoSQL¡¢JavaScript¡¢HTML5¡¢CSS3µÈIT¼¼Êõ£¬¸üºÃµØÓü¼Êõ¸Ä±äÊÀ½ç£¬ÊdzÌÐòԱѧϰ³É³¤µÄºÃµØ·½¡£

[תÔØ]nginx rewrite¹æÔò(2)

PHP´úÂë  2011-05-18 07:47:35  ×÷Õß: ºÆº£´úÂëÍø  ÔĶÁ()  ÆÀÂÛ   ×ֺţº´óÖÐС  ¶©ÔÄ

Îļþ·´µÁÁ´²¢ÉèÖùýÆÚʱ¼ä
ÕâÀïµÄreturn 412 Ϊ×Ô¶¨ÒåµÄhttp״̬Â룬ĬÈÏΪ403£¬·½±ãÕÒ³öÕýÈ·µÄµÁÁ´µÄÇëÇó
¡°rewrite ^/ http://leech.c1gstudio.com/leech.gif;¡±ÏÔʾһÕÅ·ÀµÁÁ´Í¼Æ¬
¡°access_log off;¡±²»¼Ç¼·ÃÎÊÈÕÖ¾£¬¼õÇáѹÁ¦
¡°expires 3d¡±ËùÓÐÎļþ3ÌìµÄä¯ÀÀÆ÷»º´æ

  1. location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
  2. valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194;
  3. if ($invalid_referer) {
  4. rewrite ^/ http://leech.c1gstudio.com/leech.gif;
  5. return 412;
  6. break;
  7. }
  8. access_log   off;
  9. root /opt/lampp/htdocs/web;
  10. expires 3d;
  11. break;
  12. }

Ö»³äÐí¹Ì¶¨ip·ÃÎÊÍøÕ¾£¬²¢¼ÓÉÏÃÜÂë

  1. root  /opt/htdocs/www;
  2. allow   208.97.167.194;
  3. allow   222.33.1.2;
  4. allow   231.152.49.4;
  5. deny    all;
  6. auth_basic ¡°C1G_ADMIN¡±;
  7. auth_basic_user_file htpasswd;

½«¶à¼¶Ä¿Â¼ÏµÄÎļþת³ÉÒ»¸öÎļþ£¬ÔöÇ¿seoЧ¹û
/job-123-456-789.html Ö¸Ïò/job/123/456/789.html

  1. 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/

  1. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

ÉÏÃæÀý×ÓÓиöÎÊÌâÊÇ·ÃÎÊ/shanghai ʱ½«²»»áÆ¥Åä

  1. rewrite ^/([0-9a-z]+)job$ /area/$1/ last;
  2. 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²»Êǵģ¬ËùÒÔûÓÐЧ¹û

  1. if (-d $request_filename){
  2. rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  3. }

ÖªµÀÔ­Òòºó¾ÍºÃ°ìÁË£¬ÈÃÎÒÊÖ¶¯Ìøת°É

  1. rewrite ^/([0-9a-z]+)job$ /$1job/ permanent;
  2. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

ÎļþºÍĿ¼²»´æÔÚµÄʱºòÖض¨Ïò£º

  1. if (!-e $request_filename) {
  2. proxy_pass http://127.0.0.1;
  3. }

ÓòÃûÌøת

  1. server
  2. {
  3. listen       80;
  4. server_name  jump.c1gstudio.com;
  5. index index.html index.htm index.php;
  6. root  /opt/lampp/htdocs/www;
  7. rewrite ^/ http://www.c1gstudio.com/;
  8. access_log  off;
  9. }

¶àÓòÃûתÏò

  1. server_name  www.c1gstudio.com www.c1gstudio.net;
  2. index index.html index.htm index.php;
  3. root  /opt/lampp/htdocs;
  4. if ($host ~ ¡°c1gstudio\.net¡±) {
  5. rewrite ^(.*) http://www.c1gstudio.com$1 permanent;
  6. }

Èý¼¶ÓòÃûÌøת

  1. if ($http_host ~* ¡°^(.*)\.i\.c1gstudio\.com$¡±) {
  2. rewrite ^(.*) http://top.yingjiesheng.com$1;
  3. break;
  4. }

ÓòÃû¾µÏò

  1. server
  2. {
  3. listen       80;
  4. server_name  mirror.c1gstudio.com;
  5. index index.html index.htm index.php;
  6. root  /opt/lampp/htdocs/www;
  7. rewrite ^/(.*) http://www.c1gstudio.com/$1 last;
  8. access_log  off;
  9. }

ij¸ö×ÓĿ¼×÷¾µÏò

  1. location ^~ /zhaopinhui {
  2. rewrite ^.+ http://zph.c1gstudio.com/ last;
  3. break;
  4. }

discuz ucenter home (uchome) rewrite

  1. rewrite ^/(space|network)-(.+)\.html$ /$1.php?rewrite=$2 last;
  2. rewrite ^/(space|network)\.html$ /$1.php last;
  3. rewrite ^/([0-9]+)$ /space.php?uid=$1 last;

discuz 7 rewrite

  1. rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
  2. rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
  3. rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\=$4&page=$3 last;
  4. rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
  5. rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;
  6. rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last;

¸ødiscuzij°æ¿éµ¥¶ÀÅäÖÃÓòÃû

  1. server_name  bbs.c1gstudio.com news.c1gstudio.com;

  2. location = / {
  3. if ($http_host ~ news\.c1gstudio.com$) {
  4. rewrite ^.+ http://news.c1gstudio.com/forum-831-1.html last;
  5. break;
  6. }
  7. }

discuz ucenter Í·Ïñ rewrite ÓÅ»¯

  1. location ^~ /ucenter {
  2. location ~ .*\.php?$
  3. {
  4. #fastcgi_pass  unix:/tmp/php-cgi.sock;
  5. fastcgi_pass  127.0.0.1:9000;
  6. fastcgi_index index.php;
  7. include fcgi.conf;
  8. }

  9. location /ucenter/data/avatar {
  10. log_not_found off;
  11. access_log   off;
  12. location ~ /(.*)_big\.jpg$ {
  13. error_page 404 /ucenter/images/noavatar_big.gif;
  14. }
  15. location ~ /(.*)_middle\.jpg$ {
  16. error_page 404 /ucenter/images/noavatar_middle.gif;
  17. }
  18. location ~ /(.*)_small\.jpg$ {
  19. error_page 404 /ucenter/images/noavatar_small.gif;
  20. }
  21. expires 300;
  22. break;
  23. }
  24. }

jspace rewrite

  1. location ~ .*\.php?$
  2. {
  3. #fastcgi_pass  unix:/tmp/php-cgi.sock;
  4. fastcgi_pass  127.0.0.1:9000;
  5. fastcgi_index index.php;
  6. include fcgi.conf;
  7. }

  8. location ~* ^/index.php/
  9. {
  10. rewrite ^/index.php/(.*) /index.php?$1 break;
  11. fastcgi_pass  127.0.0.1:9000;
  12. fastcgi_index index.php;
  13. include fcgi.conf;
  14. }

ÁíÍâÕâÀﻹÓÐÒ»¸ö¹¤¾ß¿ÉÒÔÖ±½Ó°Ñ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

http://www.divmy.com/


±¾ÎĵØÖ·:http://www.it300.com/article-3739.html

ÆÀÂÛ

Óû§Ãû£º (*)

ÓÊ   Ï䣺 (*)

Íø   Õ¾£º

ÄÚ   ÈÝ£º (*)

ÍƼöÐÅÏ¢

ÈÈÃÅÐÅÏ¢

×î½ü¸üÐÂ

±êÇ©(TAG)ÔÆ

¡Á
¶©ÔÄ
Êý¾ÝÕýÔÚ¼ÓÔØÖС­