NginxÔõÑùʵÏÖ»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖÃ
NginxÔõÑùʵÏÖ»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖã¬ÐèÒªÏêϸ´úÂëʾÀý
NginxÊÇÒ»¿î¸ßÐÔÄܵÄHTTPºÍ·´ÏòÊðÀíЧÀÍÆ÷£¬ÌṩÁËÎÞаµÄÉèÖÃÑ¡ÏîÀ´ÊµÏÖ»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖá£ÔÚ±¾ÆªÎÄÕÂÖУ¬ÎÒÃǽ«ÏêϸÏÈÈÝÔõÑùÉèÖÃNginxÀ´ÊµÏÖ»ùÓÚÓòÃûµÄÐéÄâÖ÷»ú£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚNginxµÄÉèÖÃÎļþÖÐÌí¼ÓÐéÄâÖ÷»úµÄÉèÖÿ顣ÔÚUbuntuϵͳÉÏ£¬Ä¬ÈϵÄÉèÖÃÎļþ·¾¶Îª/etc/nginx/nginx.conf¡£ÇëʹÓÃÎı¾±à¼Æ÷·¿ª¸ÃÎļþ£¬²¢ÏòÆäÖÐÌí¼ÓÒÔÏ´úÂ룺
http { server { listen 80; server_name example.com; root /var/www/example.com/html; index index.html; } server { listen 80; server_name example.org; root /var/www/example.org/html; index index.html; } # Ìí¼Ó¸ü¶àµÄÐéÄâÖ÷»úÉèÖÿé... }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊö´úÂëÖУ¬ÎÒÃǽç˵ÁËÁ½¸öÐéÄâÖ÷»ú£ºexample.comºÍexample.org¡£Ã¿¸öÐéÄâÖ÷»úÉèÖÿé°üÀ¨ÁËÒÔϼ¸¸öÒªº¦ÉèÖÃÏ
listen£ºÖ¸¶¨ÐéÄâÖ÷»ú¼àÌýµÄ¶Ë¿ÚºÅ£¬ÕâÀïÎÒÃÇʹÓÃÁË80¶Ë¿Ú¡£
server_name£ºÖ¸¶¨ÐéÄâÖ÷»ú¶ÔÓ¦µÄÓòÃû»òIPµØµã¡£ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃÇ»®·ÖʹÓÃÁËexample.comºÍexample.org¡£
root£ºÖ¸¶¨ÐéÄâÖ÷»úµÄ¸ùĿ¼¡£ÕâÀïÎÒÃǼÙÉèÿ¸öÐéÄâÖ÷»úµÄÍøÒ³Îļþ¶¼´æ·ÅÔÚ²î±ðµÄĿ¼Ï¡£
index£ºÖ¸¶¨ÐéÄâÖ÷»úµÄĬÈÏÊ×Ò³Îļþ¡£
½ÓÏÂÀ´£¬ÎÒÃÇÐèҪȷ±£ÐéÄâÖ÷»úµÄÍøÒ³ÎļþĿ¼±£´æ£¬²¢ÇÒ¾ßÓÐ׼ȷµÄÎļþȨÏÞ¡£ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃǼÙÉèexample.comµÄÍøÒ³ÎļþĿ¼Ϊ/var/www/example.com/html£¬example.orgµÄÍøÒ³ÎļþĿ¼Ϊ/var/www/example.org/html¡£Çëƾ֤ÏÖÕæÏàÐν¨ÉèÕâЩĿ¼£¬²¢È·±£NginxÓлá¼ûȨÏÞ¡£
Íê³ÉÉÏÊöÉèÖúó£¬ÉúÑIJ¢Í˳öNginxµÄÉèÖÃÎļþ¡£È»ºó£¬Ê¹ÓÃÒÔÏÂÏÂÁîÖØмÓÔØNginxÉèÖÃÎļþ£º
sudo nginx -s reload
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬ÎÒÃÇÒѾÍê³ÉÁË»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖᣵ±Óû§Í¨¹ýä¯ÀÀÆ÷»á¼ûexample.com»òexample.orgʱ£¬Nginx»áƾ֤ÇëÇóµÄÓòÃûÀ´Ñ¡Ôñ¶ÔÓ¦µÄÐéÄâÖ÷»ú¾ÙÐд¦Àí¡£
ÈôÊÇÄãÓиü¶àµÄÓòÃûÐèÒªÉèÖÃÐéÄâÖ÷»ú£¬Çëƾ֤ÉÏÊöʾÀýÌí¼Ó¸ü¶àµÄÐéÄâÖ÷»úÉèÖÿ飬²¢ÏìÓ¦µØÐÞ¸Äserver_nameºÍrootÉèÖÃÏî¡£
×îºó£¬ÎÒÃÇÌṩÒÔÏÂһЩ³£ÓõÄNginxÉèÖÃÖ¸ÁîÀ´½øÒ»²½ÓÅ»¯»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖãº
access_log£ºÓÃÓÚÈ·¶¨ÊÇ·ñÌìÉú»á¼ûÈÕÖ¾ÒÔ¼°ÈÕÖ¾µÄ´æ·ÅλÖá£
error_log£ºÓÃÓÚÈ·¶¨ÊÇ·ñÌìÉú¹ýʧÈÕÖ¾ÒÔ¼°ÈÕÖ¾µÄ´æ·ÅλÖá£
location£ºÓÃÓÚ½øÒ»²½¶¨ÖÆÐéÄâÖ÷»úµÄÐÐΪ£¬ºÃ±ÈÉèÖÃURLÖØд¹æÔò»ò·´ÏòÊðÀí¡£
ͨ¹ýÎÞаµØʹÓÃÒÔÉÏÖ¸ÁÄã¿ÉÒÔ¶ÔÐéÄâÖ÷»ú¾ÙÐÐÔ½·¢Ï¸ÄåµÄÉèÖúÍÓÅ»¯¡£
×ܽ᣺±¾ÎÄÏêϸÏÈÈÝÁËÔõÑùʹÓÃNginxʵÏÖ»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖ㬲¢ÌṩÁËÏêϸµÄ´úÂëʾÀý¡£Í¨¹ýƾ֤ʾÀýÉèÖÃNginxµÄÐéÄâÖ÷»ú£¬ÎÒÃÇ¿ÉÒÔÇáËɵØΪ¶à¸öÓòÃûÍйܲî±ðµÄÍøÕ¾ÄÚÈÝ£¬Ìṩ¸üºÃµÄÓû§ÌåÑ顣ϣÍûÕâƪÎÄÕ¹ØÓÚѧϰNginxµÄͬÑâÃÇÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇNginxÔõÑùʵÏÖ»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡