ÏêϸÏÈÈÝNginxЧÀÍÆ÷µÄÔÉúÄ£¿éºÍµÚÈý·½²å¼þµÄ¼¯³ÉºÍʹÓÃÒªÁì
nginxЧÀÍÆ÷ÊÇÒ»¿î¸ßÐÔÄܵÄwebЧÀÍÆ÷Èí¼þ£¬ËüµÄÀ©Õ¹ÐÔºÜÊÇÇ¿Ê¢£¬Ö§³ÖÔÉúÄ£¿éºÍµÚÈý·½²å¼þµÄ¼¯³É¡£±¾ÎĽ«ÏêϸÏÈÈÝnginxЧÀÍÆ÷µÄÔÉúÄ£¿éºÍµÚÈý·½²å¼þµÄ¼¯³ÉºÍʹÓÃÒªÁ죬²¢¸½ÉÏ´úÂëʾÀý£¬ÒÔ×ÊÖú¶ÁÕ߸üºÃµØÃ÷È·ºÍÓ¦Óá£
Ò»¡¢NginxÔÉúÄ£¿é
NginxµÄÔÉúÄ£¿éÊÇÖ¸ÓÉNginx¹Ù·½¿ª·¢ºÍά»¤µÄ¹¦Ð§Ä£¿é£¬°üÀ¨½¹µãÄ£¿é¡¢HTTPÄ£¿é¡¢mailÄ£¿éµÈ¡£ÔÚNginxµÄÉèÖÃÎļþÖУ¬¿ÉÒÔͨ¹ýÉèÖÃÖ¸ÁîÀ´ÆôÓûò½ûÓÃÕâЩģ¿é¡£
½¹µãÄ£¿é
½¹µãÄ£¿éÊÇNginxЧÀÍÆ÷µÄ»ù´¡Ä£¿é£¬°üÀ¨½¹µã¹¦Ð§ºÍ»ù±¾ÉèÖÃÖ¸Áî¡£ÀýÈ磬eventsÄ£¿éÓÃÓÚ´¦ÀíÅþÁ¬ÇëÇóºÍÊÂÎñµÄÇý¶¯£¬httpÄ£¿éÓÃÓÚ´¦ÀíHTTPÐÒéÇëÇóµÈ¡£
HTTPÄ£¿é
HTTPÄ£¿éÌṩÁË´¦ÀíHTTPÇëÇóµÄ¹¦Ð§£¬°üÀ¨HTTPÊðÀí¡¢¸ºÔØƽºâ¡¢»º´æ¡¢·´ÏòÊðÀíµÈ¡£Í¨¹ýÉèÖÃÖ¸Á¿ÉÒÔÎÞаÉèÖÃHTTPÄ£¿éµÄÐÐΪ¡£ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄHTTPÄ£¿éÉèÖÃʾÀý£º
http { server { listen 80; server_name example.com; location / { root /path/to/website; index index.html; } } }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃʾÀýÖУ¬listenÖ¸ÁîÓÃÓÚÖ¸¶¨¼àÌýµÄ¶Ë¿Ú£¬server_nameÖ¸ÁîÓÃÓÚÖ¸¶¨Ð§ÀÍÆ÷Ãû£¬locationÖ¸ÁîÓÃÓÚÖ¸¶¨URL·¾¶Æ¥Åä¹æÔòºÍ¶ÔÓ¦µÄ´¦ÀíÂß¼¡£
mailÄ£¿é
mailÄ£¿éÌṩÁË´¦ÀíÓʼþЧÀ͵Ĺ¦Ð§£¬ÀýÈçSMTPÊðÀí¡¢POP3ÊðÀíµÈ¡£¿ÉÒÔͨ¹ýÉèÖÃÖ¸ÁîÀ´ÆôÓûò½ûÓÃmailÄ£¿é¡£ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄmailÄ£¿éÉèÖÃʾÀý£º
mail { server { listen 25; protocol smtp; server_name mail.example.com; auth_http localhost:80/auth.php; } }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃʾÀýÖУ¬listenÖ¸ÁîÓÃÓÚÖ¸¶¨¼àÌýµÄ¶Ë¿Ú£¬protocolÖ¸ÁîÓÃÓÚÖ¸¶¨ÐÒéÀàÐÍ£¬server_nameÖ¸ÁîÓÃÓÚÖ¸¶¨Ð§ÀÍÆ÷Ãû£¬auth_httpÖ¸ÁîÓÃÓÚÖ¸¶¨ÈÏÖ¤½Ó¿Ú¡£
¶þ¡¢µÚÈý·½²å¼þ
³ýÁËÔÉúÄ£¿é£¬Nginx»¹Ö§³ÖµÚÈý·½²å¼þµÄ¼¯³É¡£µÚÈý·½²å¼þ¿ÉÒÔÀ©Õ¹NginxµÄ¹¦Ð§£¬ÀýÈçÔöÌíSSLÖ§³Ö¡¢ÔöÌíHTTP2Ö§³ÖµÈ¡£ÒÔÏÂÊÇÒ»¸öʹÓõÚÈý·½²å¼þµÄÉèÖÃʾÀý£º
http { server { listen 443 ssl http2; server_name example.com; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem; } }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃʾÀýÖУ¬sslÖ¸ÁîÓÃÓÚÆôÓÃSSLÖ§³Ö£¬http2Ö¸ÁîÓÃÓÚÆôÓÃHTTP2Ö§³Ö£¬ssl_certificateÖ¸ÁîÓÃÓÚÖ¸¶¨SSLÖ¤ÊéµÄ·¾¶£¬ssl_certificate_keyÖ¸ÁîÓÃÓÚÖ¸¶¨SSLÖ¤ÊéµÄ˽Կ·¾¶¡£
Èý¡¢´úÂëʾÀý
ÒÔÏÂÊÇÒ»¸öÍêÕûµÄNginxЧÀÍÆ÷ÉèÖÃʾÀý£¬°üÀ¨ÔÉúÄ£¿éºÍµÚÈý·½²å¼þµÄ¼¯³É£º
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name example.com; location / { root /path/to/website; index index.html; } } server { listen 443 ssl http2; server_name example.com; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem; location / { root /path/to/website; index index.html; } } }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃʾÀýÖУ¬worker_processesÖ¸ÁîÓÃÓÚÖ¸¶¨NginxµÄÀú³ÌÊý£¬eventsÖ¸ÁîÓÃÓÚÉèÖò¢·¢ÅþÁ¬Êý£¬httpÖ¸ÁîÓÃÓÚÉèÖÃHTTPÄ£¿é£¬includeÖ¸ÁîÓÃÓÚÒýÈëmime.typesÎļþ£¬default_typeÖ¸ÁîÓÃÓÚÉèÖÃĬÈϵÄÄÚÈÝÀàÐÍ£¬sendfileÖ¸ÁîÓÃÓÚÆôÓøßЧµÄÎļþ´«Ê书Ч£¬keepalive_timeoutÖ¸ÁîÓÃÓÚÉèÖó¤ÅþÁ¬³¬Ê±Ê±¼ä¡£
ͨ¹ýÒÔÉϵÄÏÈÈÝ£¬ÎÒÃÇ¿ÉÒÔÏàʶµ½NginxЧÀÍÆ÷µÄÔÉúÄ£¿éºÍµÚÈý·½²å¼þµÄ¼¯³ÉºÍʹÓÃÒªÁ졣ͨ¹ýºÏÀíÉèÖÃÕâЩģ¿éºÍ²å¼þ£¬¿ÉÒÔ³ä·ÖÑéÕ¹NginxЧÀÍÆ÷µÄÐÔÄܺ͹¦Ð§ÓÅÊÆ¡£Ï£Íû±¾ÎĶԶÁÕßÔÚʹÓÃNginxЧÀÍÆ÷ʱÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÏêϸÏÈÈÝNginxЧÀÍÆ÷µÄÔÉúÄ£¿éºÍµÚÈý·½²å¼þµÄ¼¯³ÉºÍʹÓÃÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡