nginxÓòÃûÔõôÓÃ
ʹÓÃnginxÉèÖÃÓòÃû£¬ÐèÒª£º½¨ÉèÐéÄâÖ÷»úÉèÖã¬Ö¸¶¨ÓòÃûµÄÉèÖá£ÉèÖüàÌý¶Ë¿Ú£¨Èç¶Ë¿Ú80£©ºÍЧÀÍÆ÷Ãû³Æ£¨Èç¡°example.com¡±£©¡£ÉèÖÃÍøÕ¾ÎļþµÄ¸ùĿ¼£¨Èç¡°/var/www/example.com/public¡±£©¡£ÉèÖÃĬÈÏÒ³Ã棨Èç¡°index.php¡±»ò¡°index.html¡±£©¡£Ó¦ÓÃÉèÖøü¸Ä£¨Ê¹Óá°sudo systemctl reload nginx¡±»ò¡°sudo systemctl restart nginx¡±£©¡£ÑéÖ¤ÉèÖã¨Ê¹ÓÃcurl»òwebä¯ÀÀÆ÷»á¼û¡°example.com¡±£©
ʹÓà nginx ÉèÖÃÓòÃû
nginxÊÇÒ»ÖÖÇ¿Ê¢µÄwebЧÀÍÆ÷£¬¿ÉÓÃÓÚÖÎÀíÍøÕ¾Á÷Á¿²¢ÉèÖÃÓòÃû¡£ÒÔÏÂÊÇʹÓÃnginxÉèÖÃÓòÃûµÄ°ì·¨£º
1. ½¨ÉèÐéÄâÖ÷»úÉèÖÃ
½¨ÉènginxÉèÖÃÎļþÒÔ½ç˵ÓòÃûµÄÉèÖᣴËÉèÖÃÎļþͨ³£Î»ÓÚ /etc/nginx/conf.d/ Ŀ¼ÖС£¹ØÓÚÓòÃûΪ¡°example.com¡±µÄÐéÄâÖ÷»ú£¬ÉèÖÃÎļþÈçÏ£º
server { listen 80; server_name example.com www.example.com; root /var/www/example.com/public; index index.php index.html; }
µÇ¼ºó¸´ÖÆ
2. ÉèÖüàÌý¶Ë¿ÚºÍЧÀÍÆ÷Ãû³Æ
listen 80;£º´ËÐÐÖ¸¶¨Ð§ÀÍÆ÷½«ÔÚ¶Ë¿Ú 80£¨±ê×¼ HTTP ¶Ë¿Ú£©ÉϼàÌý´«ÈëÇëÇó¡£
server_name example.com www.example.com;£º´ËÐÐÖ¸¶¨ÓòÃûºÍÓÖÃû£¬ÔÚÕâÖÖÇéÐÎÏÂΪ¡°example.com¡±ºÍ¡°www.example.com¡±¡£
3. ÉèÖøùĿ¼
root /var/www/example.com/public;£º´ËÐÐÖ¸¶¨ÍøÕ¾ÎļþµÄ¸ùĿ¼¡£
4. ÉèÖÃĬÈÏÒ³Ãæ
index index.php index.html;£º´ËÐÐÖ¸¶¨µ±ÇëÇó¸ùĿ¼ʱҪ²éÕÒµÄĬÈÏÒ³Ãæ¡£ËüÊ×ÏȲéÕÒ¡°index.php¡±£¬ÈôÊDz»±£´æ£¬Ôò²éÕÒ¡°index.html¡±¡£
5. Ó¦ÓÃÉèÖÃ
Ó¦ÓÃ¶Ô nginx ÉèÖÃËù×öµÄ¸ü¸Ä£º
Ubuntu/Debian: ÔËÐÐ sudo systemctl reload nginx¡£
CentOS/Fedora: ÔËÐÐ sudo systemctl restart nginx¡£
6. ÑéÖ¤ÉèÖÃ
ʹÓà curl »ò Web ä¯ÀÀÆ÷ÑéÖ¤ÓòÃûÊÇ·ñÒÑ׼ȷÉèÖãº
curl: ÔËÐÐ curl -I example.com¡£
Web ä¯ÀÀÆ÷: »á¼û¡°https://example.com¡±¡£
ÈôÊÇÉèÖÃ׼ȷ£¬ÄúÓ¦¸ÃÄܹ»¿´µ½ÍøÕ¾µÄÄÚÈÝ»òÊÕµ½ HTTP 200 ´úÂë¡£
ÒÔÉϾÍÊÇnginxÓòÃûÔõôÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡