尊龙凯时人生就是搏

NginxÔõÑùʵÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖÃ

NginxÔõÑùʵÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖÃ

Nginx×÷Ϊһ¸ö¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷ £¬¾ßÓÐÇ¿Ê¢µÄÉèÖù¦Ð§¡£ÆäÖÐ £¬ÇëÇóÖØд¹¦Ð§ÊÇNginxÖÐÒ»¸öºÜÊÇÖ÷ÒªµÄ¹¦Ð§Ö®Ò»¡£Í¨¹ýÇëÇóÖØд £¬ÎÒÃÇ¿ÉÒÔ¶Ô¿Í»§¶ËÇëÇóÖеÄURI¾ÙÐÐÐÞ¸Ä £¬ÊµÏÖURLÖض¨Ïò¡¢ÇëÇó²ÎÊý´¦ÀíµÈ¹¦Ð§¡£¶ø»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖà £¬¿ÉÒÔƾ֤²î±ðµÄÇëÇó²ÎÊýÀ´¾ÙÐвî±ðµÄURLÖØд £¬´Ó¶øʵÏÖÔ½·¢ÎÞаµÄÇëÇó´¦Àí¡£

ÏÂÃæÎÒÃǽ«ÏêϸÏÈÈÝÔõÑùÔÚNginxÖÐʵÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖá£

Ò»¡¢ÉèÖÃÉÏÏÂÎÄ

ÔÚNginxÖÐ £¬¿ÉÒÔͨ¹ýÔÚ²î±ðµÄÉèÖÃÉÏÏÂÎÄÖоÙÐÐÇëÇóÖØдµÄÉèÖᣳ£¼ûµÄÉèÖÃÉÏÏÂÎÄ°üÀ¨server¡¢locationµÈ¡£ÔÚʵÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдʱ £¬ÎÒÃÇͨ³ £»áÔÚlocationÉèÖÿéÖоÙÐÐÉèÖá£

ÒÔÏÂÊÇÒ»¸ö»ù±¾µÄNginxÉèÖÃÎļþ£º

server {
    listen 80;
    server_name example.com;

    location / {
        # ÕâÀï¾ÙÐÐÇëÇóÖØдµÄÉèÖÃ
    }
}

µÇ¼ºó¸´ÖÆ

¶þ¡¢»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖÃ

ÔÚNginxÖÐ £¬¿ÉÒÔʹÓÃifÖ¸ÁîºÍrewriteÖ¸ÁîÀ´ÊµÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖá£ÏÂÃæÊÇÒ»¸öʾÀý £¬ÎÒÃǽ«Æ¾Ö¤ÇëÇó²ÎÊýidµÄÖµÀ´¾ÙÐвî±ðµÄURLÖØд£º

location / {
    if ($arg_id = 1) {  # ÈôÊÇÇëÇó²ÎÊýidµÄֵΪ1
        rewrite ^/article/(.*)$ /article-1/$1 last;  # ½« /article/xxx ÖØдΪ /article-1/xxx
    }
    if ($arg_id = 2) {  # ÈôÊÇÇëÇó²ÎÊýidµÄֵΪ2
        rewrite ^/article/(.*)$ /article-2/$1 last;  # ½« /article/xxx ÖØдΪ /article-2/xxx
    }
    # ÆäËûÇéÐÎ...
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄÉèÖÃÖÐ £¬ÎÒÃÇͨ¹ýifÖ¸Áî¶ÔÇëÇó²ÎÊýidµÄÖµ¾ÙÐÐÅжÏ £¬ÈôÊÇÖª×ãÌõ¼þ £¬ÔòʹÓÃrewriteÖ¸Áî¶ÔURI¾ÙÐÐÖØд¡£

Èý¡¢Ê¹ÓÃMapÄ£¿é¾ÙÐÐÇëÇóÖØдÉèÖÃ

³ýÁËʹÓÃifÖ¸ÁîºÍrewriteÖ¸Áî £¬»¹¿ÉÒÔʹÓÃNginxµÄmapÄ£¿éÀ´ÊµÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖá£mapÄ£¿é¿ÉÒÔ½ç˵һ¸ö±äÁ¿Ó³Éä±í £¬Æ¾Ö¤ÇëÇó²ÎÊýµÄÖµÀ´Ó³Éä¶ÔÓ¦µÄÖØд¹æÔò¡£ÒÔÏÂÊÇÒ»¸öʹÓÃmapÄ£¿éµÄʾÀý£º

map $arg_id $id_mapping {
    1 /article-1/;
    2 /article-2/;
    default /article/;
}

location / {
    rewrite ^/article/(.*)$ $id_mapping$1 last;  # ƾ֤ÇëÇó²ÎÊýidµÄÖµ¾ÙÐÐÖض¨Ïò
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄÉèÖÃÖÐ £¬ÎÒÃÇʹÓÃmapÄ£¿é½ç˵ÁËÒ»¸ö±äÁ¿Ó³Éä±í$id_mapping £¬Æ¾Ö¤ÇëÇó²ÎÊýidµÄÖµÀ´Ó³Éä²î±ðµÄÖØд¹æÔò¡£È»ºóÔÚlocationÉèÖÿéÖÐʹÓÃrewriteÖ¸Áî¾ÙÐÐÇëÇóÖØд £¬Æ¾Ö¤Ó³Éä±íµÄÖµÀ´ÖØдURI¡£

ËÄ¡¢×¢ÖØÊÂÏî

ÔÚʵÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖÃʱ £¬ÐèҪעÖØÒÔϼ¸µã£º

Ö»¹Ü×èÖ¹¹ý¶àµÄifÖ¸Áî £¬¹ý¶àµÄifÖ¸Áî»á¶ÔÐÔÄܱ¬·¢Ò»¶¨µÄÓ°Ïì £»

ʹÓÃmapÄ£¿éÄܹ»Ô½·¢ÇåÎúµØ½ç˵±äÁ¿Ó³Éä±í £¬ÔöÇ¿ÁËÉèÖõĿɶÁÐԺͿÉά»¤ÐÔ £»

µ±ÉèÖýÏΪÖØ´óʱ £¬½¨ÒéÏȾÙÐмòÆӵIJâÊÔ £¬È·±£ÇëÇó²ÎÊýµÄÖµÄܹ»×¼È·´¥·¢ÏìÓ¦µÄÇëÇóÖØд¹æÔò¡£

½áÓï

ͨ¹ý±¾ÎĵÄÏÈÈÝ £¬ÎÒÃÇÏàʶÁËÔõÑùÔÚNginxÖÐʵÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖá£ÎÞÂÛÊÇʹÓÃifÖ¸ÁîºÍrewriteÖ¸Áî £¬ÕÕ¾ÉʹÓÃmapÄ£¿é £¬¶¼Äܹ»ÊµÏÖÎÞаµÄÇëÇóÖØд¹¦Ð§¡£Í¬Ê± £¬ÔÚÉèÖÃʱÐèҪעÖØÐÔÄܺͿÉά»¤ÐÔ £¬×èֹ̫¹ýÖØ´óµÄÉèÖà £¬ÒÔ°ü¹ÜЧÀÍÆ÷µÄÎȹÌÐÔºÍÐÔÄÜ¡£

Ï£Íû±¾ÎÄÄܹ»¶Ô¸÷ÈËÃ÷È·NginxµÄÇëÇóÖØд¹¦Ð§ÓÐËù×ÊÖú £¬Í¬Ê±¶ÔÉèÖÃNginxʱԽ·¢ÎÞаµØ´¦ÀíÇëÇó²ÎÊýÓÐËùÆô·¢¡£

ÒÔÉϾÍÊÇNginxÔõÑùʵÏÖ»ùÓÚÇëÇó²ÎÊýµÄÇëÇóÖØдÉèÖõÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ