Ôõô°Ñnginx»á¿´·¨Ö·ÉèÖóÉЧÀÍÆ÷ip
ÒªÔÚ nginx Öн«»á¿´·¨Ö·ÉèÖÃΪЧÀÍÆ÷ ip£¬Ç룺ÉèÖÃЧÀÍÆ÷¿é£¬ÉèÖüàÌýµØµã£¨È磺listen 192.168.1.10:80£©ÉèÖÃЧÀÍÆ÷Ãû³Æ£¨È磺server_name example.com www.example.com£©£¬»ò½«ÆäÁô¿ÕÒÔ»á¼ûЧÀÍÆ÷ ipÉúÑIJ¢ÖØмÓÔØ nginx ÒÔÓ¦Óøü¸Ä
ÔõÑùÔÚ Nginx Öн«»á¿´·¨Ö·ÉèÖÃΪЧÀÍÆ÷ IP
ÔÚ Nginx Öн«»á¿´·¨Ö·ÉèÖÃΪЧÀÍÆ÷ IP µÄ°ì·¨£º
1. ÉèÖÃЧÀÍÆ÷¿é
ÔÚ Nginx ÉèÖÃÎļþÖУ¬ÕÒµ½»ò½¨ÉèÒªÉèÖõÄЧÀÍÆ÷¿é¡£Ð§ÀÍÆ÷¿éͨ³£Î»ÓÚ “sites-enabled” Ŀ¼ÏµÄÉèÖÃÎļþÖС£
server { ... }
µÇ¼ºó¸´ÖÆ
2. ÉèÖüàÌýµØµã
ÔÚЧÀÍÆ÷¿éÖУ¬Ìí¼Ó “listen” Ö¸ÁîÒÔÖ¸¶¨ Nginx ¼àÌýµÄ IP µØµãºÍ¶Ë¿Ú¡£
server { listen <ip-address>:<port>; ... }</port></ip-address>
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬ ÊÇЧÀÍÆ÷µÄ IP µØµã£¬ ÊÇÄúÏ£ÍûÓÃÓÚ»á¼ûÍøÕ¾µÄ¶Ë¿Ú£¨Í¨³£Îª 80£©¡£ÀýÈ磬ҪÈà Nginx ÔÚЧÀÍÆ÷ IP “192.168.1.10” É쵀 80 ¶Ë¿Ú¼àÌý£º
server { listen 192.168.1.10:80; ... }
µÇ¼ºó¸´ÖÆ
3. ÉèÖÃЧÀÍÆ÷Ãû³Æ
ÔÚЧÀÍÆ÷¿éÖУ¬Ìí¼Ó “server_name” Ö¸ÁîÒÔÖ¸¶¨Ð§ÀÍÆ÷ÏìÓ¦µÄÓòÃû»ò IP µØµã¡£
server { listen <ip-address>:<port>; server_name example.com www.example.com; ... }</port></ip-address>
µÇ¼ºó¸´ÖÆ
ÈôÊǻῴ·¨Ö·²»ÊÇÓòÃû£¬Ç뽫 “server_name” ÉèÖÃΪ¿Õ¡£
4. ÉúÑIJ¢ÖØмÓÔØ Nginx
ÉúÑÄ Nginx ÉèÖÃÎļþ²¢ÖØмÓÔØ Nginx ÒÔÓ¦Óøü¸Ä¡£
sudo systemctl reload nginx
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬µ±Äú»á¼ûÔÚ “listen” Ö¸ÁîÖÐÖ¸¶¨µÄ IP µØµãºÍ¶Ë¿Úʱ£¬Nginx ½«»áÏìÓ¦²¢ÏÔʾΪЧÀÍÆ÷ IP »á¼ûµÄÍøÕ¾¡£
ÒÔÉϾÍÊÇÔõô°Ñnginx»á¿´·¨Ö·ÉèÖóÉЧÀÍÆ÷ipµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡