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

ÆÊÎöNginxµÄÐéÄâÖ÷»úÉèÖúÍÓòÃûÆÊÎöʵÏÖϸ½Ú

ÆÊÎönginxµÄÐéÄâÖ÷»úÉèÖúÍÓòÃûÆÊÎöʵÏÖϸ½Ú

NginxÊÇÒ»¿î¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷£¬ÆÕ±éÓÃÓÚ»¥ÁªÍøÁìÓò¡£ÐéÄâÖ÷»úÉèÖúÍÓòÃûÆÊÎöÊÇNginxµÄÖ÷Òª¹¦Ð§Ö®Ò»£¬±¾ÎĽ«ÏêϸÆÊÎöNginxµÄÐéÄâÖ÷»úÉèÖúÍÓòÃûÆÊÎöµÄʵÏÖϸ½Ú£¬²¢¸ø³ö´úÂëʾÀý¡£

Ò»¡¢ÐéÄâÖ÷»úÉèÖÃ

ÐéÄâÖ÷»úÊÇÖ¸ÔÚһ̨ÎïÀíЧÀÍÆ÷ÉÏͬʱÍйܶà¸öÓòÃûµÄÄÜÁ¦¡£Nginxͨ¹ýÉèÖòî±ðµÄÐéÄâÖ÷»úÀ´ÊµÏÖÕâÒ»¹¦Ð§¡£

·­¿ªNginxµÄÉèÖÃÎļþnginx.conf£¬Ò»Ñùƽ³£Î»ÓÚ/etc/nginxĿ¼Ï¡£

ÔÚhttp¿éÖÐÌí¼ÓÒÔÏ´úÂ룺

http {
    server {
        listen 80;
        server_name example.com;
        root /var/www/example.com;
        index index.html;
    }

    server {
        listen 80;
        server_name example2.com;
        root /var/www/example2.com;
        index index.html;
    }
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏÉèÖýç˵ÁËÁ½¸öÐéÄâÖ÷»ú£¬»®·Ö¶ÔÓ¦example.comºÍexample2.comÁ½¸öÓòÃû¡£Ã¿¸öÐéÄâÖ÷»úµÄÉèÖÿéÖаüÀ¨Á˼àÌýµÄ¶Ë¿Ú¡¢Ð§ÀÍÆ÷Ãû³Æ¡¢¸ùĿ¼ºÍĬÈÏË÷ÒýÎļþ¡£

ÉúÑIJ¢Í˳önginx.confÎļþ¡£

ÖØмÓÔØNginxÉèÖã¬Ê¹ÆäÉúЧ£ºsudo nginx -s reload¡£

ͨ¹ýÒÔÉÏÉèÖã¬Nginx»áƾ֤ÇëÇóµÄÓòÃû½«ÇëÇóת·¢¸øÏìÓ¦µÄÐéÄâÖ÷»ú¾ÙÐд¦Àí¡£

¶þ¡¢ÓòÃûÆÊÎöʵÏÖϸ½Ú

±à¼­/etc/hostsÎļþ£¬½«example.comºÍexample2.comÁ½¸öÓòÃûÖ¸ÏòЧÀÍÆ÷IPµØµã£¬ÀýÈ磺

127.0.0.1 example.com
127.0.0.1 example2.com

µÇ¼ºó¸´ÖÆ

ÕâÑùÍâµØ²âÊÔʱ£¬¿ÉÒÔÖ±½Ó»á¼ûÓòÃû£¬¶øÎÞÐè¾ÙÐÐÓòÃûÆÊÎö¡£

ÔÚÓòÃû×¢²áÉÌ´¦ÉèÖÃÓòÃûÆÊÎö£¬½«ÓòÃûÖ¸ÏòЧÀÍÆ÷IPµØµã¡£

ͨ¹ýDNSЧÀÍÆ÷¾ÙÐÐÓòÃûÆÊÎö£¬½«Óû§»á¼ûµÄÓòÃûÆÊÎöΪЧÀÍÆ÷µÄIPµØµã¡£

ÔÚÉÏÊöÁ½ÖÖÇéÐÎÖУ¬Óû§»á¼ûexample.com»òexample2.comʱ£¬¶¼»áͨ¹ýÓòÃûÆÊÎö½«ÓòÃûÓ³ÉäΪЧÀÍÆ÷IPµØµã£¬ÒÔ±ãNginxÄܹ»×¼È·µØÕÒµ½¶ÔÓ¦µÄÐéÄâÖ÷»ú¾ÙÐÐÇëÇó´¦Àí¡£

´úÂëʾÀý£º

ÔÚNginxµÄÐéÄâÖ÷»úÉèÖÃÖУ¬»¹¿ÉÒÔÌí¼ÓһЩÆäËûÉèÖòÎÊý£¬ÒÔʵÏÖ¸üÎÞаµÄ¹¦Ð§¡£

ÀýÈ磬¿ÉÒÔʹÓÃrewriteÖ¸ÁîʵÏÖURLÖØд£¬½«ÇëÇóÖض¨Ïòµ½ÆäËûÒ³Ãæ¡£ÒÔÏ´úÂëʾÀý½«ÇëÇóexample.com/oldpageÖض¨Ïòµ½example.com/newpage¡£

http {
    server {
        listen 80;
        server_name example.com;
        root /var/www/example.com;
        index index.html;

        location /oldpage {
            rewrite ^/oldpage /newpage;
        }
    }
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëÖУ¬location /oldpageÉèÖý«Æ¥ÅäÒÔ/oldpage¿ªÍ·µÄURL£¬²¢Ê¹ÓÃrewriteÖ¸ÁÆäÖض¨Ïòµ½/newpage¡£

×ܽ᣺

±¾ÎÄͨ¹ýÆÊÎönginxµÄÐéÄâÖ÷»úÉèÖúÍÓòÃûÆÊÎöʵÏÖϸ½Ú£¬ÏêϸÏÈÈÝÁËNginxÔõÑùʵÏÖ¶à¸öÓòÃûµÄÍйܺÍÇëÇóת·¢¡£Í¨¹ýѧϰNginxµÄÐéÄâÖ÷»úÉèÖúÍÓòÃûÆÊÎö£¬¿ÉÒÔ¸üºÃµØÃ÷È·ºÍÓ¦ÓÃNginx£¬Ìá¸ßЧÀÍÆ÷µÄÐÔÄܺÍÎÞаÐÔ¡£

ÒÔÉϾÍÊÇÆÊÎöNginxµÄÐéÄâÖ÷»úÉèÖúÍÓòÃûÆÊÎöʵÏÖϸ½ÚµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ