×ðÁú¿­Ê±¹ÙÍøµÇ¼

NginxÖض¨ÏòÉèÖý̳Ì £¬ÊµÏÖURLת·¢ºÍץȡ

nginxÖض¨ÏòÉèÖý̳Ì £¬ÊµÏÖurlת·¢ºÍץȡ

NginxÊÇÒ»¿î¸ßÐÔÄܵĿªÔ´WebЧÀÍÆ÷ £¬Ò²¿ÉÒÔÓÃÀ´ÊµÏÖ·´ÏòÊðÀí¡¢¸ºÔØƽºâÒÔ¼°URLÖض¨ÏòµÈ¹¦Ð§ ¡£ÔÚ±¾ÆªÎÄÕÂÖÐ £¬ÎÒÃǽ«ÏÈÈÝÔõÑùͨ¹ýNginxÉèÖÃʵÏÖURLÖض¨ÏòºÍץȡµÄ¹¦Ð§ £¬²¢ÇÒÌṩÏà¹ØµÄ´úÂëʾÀý ¡£

Ò»¡¢URLת·¢

URLת·¢ÊÇÖ¸½«Ò»¸öURLÇëÇóת·¢µ½ÁíÒ»¸öURLµØµãÉÏ ¡£ÔÚNginxÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÉèÖÃÀ´ÊµÏÖURLµÄת·¢¹¦Ð§ ¡£ÒÔÏÂÊÇһЩ³£¼ûµÄURLת·¢Ê¾Àý£º

ÇëÇóת·¢

µ±Óû§ÇëÇó»á¼ûÒ»¸öÌض¨µÄURLʱ £¬ÎÒÃÇ¿ÉÒÔ½«ÇëÇóת·¢µ½Ö¸¶¨µÄURLÉÏ ¡£ÏÂÃæÊÇÒ»¸öʾÀýÉèÖãº

server {
    listen 80;
    server_name www.example.com;

    location / {
        proxy_pass http://www.new-example.com;
    }
}

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Õâ¸öÉèÖý«»á°ÑÓû§ÇëÇóת·¢µ½http://www.new-example.comÉÏ ¡£

»ùÓÚ·¾¶µÄת·¢

µ±Óû§µÄÇëÇ󷾶ƥÅäµ½Ö¸¶¨µÄ¹æÔòʱ £¬ÎÒÃÇ¿ÉÒÔ½«ÇëÇóת·¢µ½ÁíÒ»¸öURLµØµã ¡£ÒÔÏÂÊÇÒ»¸öʾÀýÉèÖãº

server {
    listen 80;
    server_name www.example.com;

    location /old {
        rewrite ^/old/(.*)$ /new/$1 break;
        proxy_pass http://www.new-example.com;
    }
}

µÇ¼ºó¸´ÖÆ

Õâ¸öÉèÖý«»á°ÑÓû§ÇëÇ󷾶ÖÐ/oldµÄ²¿·ÖÌ滻Ϊ/new £¬È»ºóÔÙ½«ÇëÇóת·¢µ½http://www.new-example.comÉÏ ¡£

»ùÓÚÓòÃûµÄת·¢

µ±Óû§ÇëÇó»á¼ûÒ»¸öÌض¨µÄÓòÃûʱ £¬ÎÒÃÇ¿ÉÒÔ½«ÇëÇóת·¢µ½ÁíÒ»¸öURLµØµã ¡£ÒÔÏÂÊÇÒ»¸öʾÀýÉèÖãº

server {
    listen 80;
    server_name www.example.com;

    location / {
        proxy_pass http://www.new-example.com;
    }
}

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Õâ¸öÉèÖý«»á°ÑÀ´×Ôwww.example.comÓòÃûµÄÇëÇóת·¢µ½http://www.new-example.comÉÏ ¡£

ÒÔÉÏÊÇһЩ³£¼ûµÄURLת·¢Ê¾Àý £¬Äã¿ÉÒÔƾ֤ÏêϸÐèÇó¾ÙÐÐÉèÖà ¡£

¶þ¡¢URLץȡ

URLץȡÊÇָͨ¹ýNginx½«Óû§ÇëÇóµÄURLÄÚÈÝץȡÏÂÀ´²¢»º´æÆðÀ´ £¬ÒÔÌá¸ß»á¼ûËÙÂÊ ¡£ÒÔÏÂÊÇÒ»¸öʾÀýÉèÖãº

http {
    # ½ç˵»º´æĿ¼
    proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m;

    server {
        listen 80;
        server_name www.example.com;

        location / {
            # »º´æÉèÖÃ
            proxy_cache my_cache;
            proxy_cache_valid 200 302 10m;
            proxy_cache_valid 404 1m;

            # ץȡÉèÖÃ
            proxy_cache_use_stale updating;
            proxy_cache_lock on;

            # ץȡÄÚÈÝ
            proxy_pass http://www.news-example.com;
        }
    }
}

µÇ¼ºó¸´ÖÆ

Õâ¸öÉèÖý«»áδÀ´×Ôwww.example.comµÄÇëÇóץȡÏÂÀ´ £¬²¢´æ´¢ÔÚ·¾¶Îª/path/to/cacheµÄĿ¼ÖÐ ¡£µ±Óû§Ôٴλá¼ûÏàͬµÄURLʱ £¬Nginx½«Ö±½Ó´Ó»º´æÖжÁÈ¡ÄÚÈÝ £¬Ìá¸ßÁË»á¼ûËÙÂÊ ¡£

×¢ÖØ£ºÒÔÉÏÖ»ÊÇÒ»¸öʾÀýÉèÖà £¬Äã¿ÉÒÔƾ֤ÏÖʵÐèÇó¾ÙÐе÷½â ¡£

×ܽá

±¾ÎÄÏÈÈÝÁËÔõÑùͨ¹ýNginxÉèÖÃʵÏÖURLת·¢ºÍץȡµÄ¹¦Ð§ £¬²¢ÌṩÁËÏà¹ØµÄ´úÂëʾÀý ¡£Í¨¹ýÎÞаµÄNginxÉèÖà £¬ÎÒÃÇ¿ÉÒÔʵÏÖÖÖÖÖURLת·¢ºÍץȡµÄÐèÇó £¬Ìá¸ßWebÓ¦ÓõÄÐÔÄܺÍÎÞаÐÔ ¡£Ï£Íû±¾ÎĶÔÄãÓÐËù×ÊÖú ¡£ÈôÊÇÓÐÈκÎÎÊÌâ £¬ÇëÔÚ̸ÂÛÇøÁôÑÔ ¡£

ÒÔÉϾÍÊÇNginxÖض¨ÏòÉèÖý̳Ì £¬ÊµÏÖURLת·¢ºÍץȡµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼ ¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý ¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ