nginxÔõôÆôÓÃstream
ÔõÑùÆôÓà nginx µÄ stream Ä£¿é£¿ÆôÓà stream Ä£¿éÐèÒªÁù¸ö°ì·¨£º×°Öà stream Ä£¿éÉèÖà nginx½¨Éè stream ЧÀÍÆ÷¿éÉèÖà stream ЧÀÍÆ÷Ñ¡ÏîÖØÆô nginxÑéÖ¤ÆôÓÃ
ÔõÑùÆôÓà Nginx µÄ Stream Ä£¿é
ÆôÓà Nginx µÄ Stream Ä£¿éºÜÊǼòÆÓ£¬Ö»ÐèÖ´ÐÐÒÔÏ°취£º
1. ×°Öà Stream Ä£¿é
Ê×ÏÈ£¬ÐèҪȷ±£ÄúÒÑ×°ÖÃÁË Nginx Stream Ä£¿é¡£ÔÚ´ó´ó¶¼ Linux ¿¯ÐаæÉÏ£¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
sudo apt install nginx-stream-module
µÇ¼ºó¸´ÖÆ
»ò£º
sudo yum install nginx-stream-module
µÇ¼ºó¸´ÖÆ
2. ÉèÖÃ Nginx
×°ÖÃÄ£¿éºó£¬ÄúÐèÒªÔÚ Nginx ÉèÖÃÎļþÖмÓÔØËü¡£·¿ª Nginx ÉèÖÃÎļþ (/etc/nginx/nginx.conf)£¬²¢ÔÚ http ¿éÖ®ÍâÌí¼ÓÒÔÏÂÐУº
load_module modules/ngx_stream_module.so;
µÇ¼ºó¸´ÖÆ
3. ½¨Éè Stream ЧÀÍÆ÷¿é
½ÓÏÂÀ´£¬ÄúÐèÒª½¨ÉèÒ»¸ö Stream ЧÀÍÆ÷¿éÀ´½ç˵½«Ê¹Óà Stream Ä£¿éµÄЧÀÍÆ÷µÄÉèÖá£ÔÚ Nginx ÉèÖÃÎļþÖУ¬Ìí¼ÓÒÔÏ£º
stream { server { listen 8080; # ÕâÀïÉèÖà Stream ЧÀÍÆ÷µÄÑ¡Ïî... } }
µÇ¼ºó¸´ÖÆ
4. ÉèÖà Stream ЧÀÍÆ÷Ñ¡Ïî
ÔÚÕâ¸ö Stream ЧÀÍÆ÷¿éÖУ¬Äú¿ÉÒÔÉèÖÃÖÖÖÖÑ¡ÏîÀ´¿ØÖÆЧÀÍÆ÷µÄÐÐΪ¡£ÀýÈ磬Äú¿ÉÒÔÖ¸¶¨Òª¼àÌýµÄ¶Ë¿Ú£¨ÔÚ±¾ÀýÖÐΪ 8080£©£¬ÒÔ¼°ÒªÊ¹ÓõÄÐÒ飨Èç TCP¡¢UDP »ò TLS£©¡£
5. ÖØÆô Nginx
×îºó£¬ÖØÐÂÆô¶¯ Nginx ÒÔÓ¦Óøü¸Ä£º
sudo systemctl restart nginx
µÇ¼ºó¸´ÖÆ
6. ÑéÖ¤ÆôÓÃ
ÏÖÔÚ£¬Stream Ä£¿éÒÑÆôÓã¬Äú¿ÉÒÔͨ¹ý¼ì²é Nginx Àú³ÌÁбíÀ´ÑéÖ¤£º
sudo systemctl status nginx | grep -i stream
µÇ¼ºó¸´ÖÆ
ÈôÊÇÊä³öÖÐÏÔʾ “ngx_stream_module (stream)”, ÔòÅú×¢ Stream Ä£¿éÒÑÀÖ³ÉÆôÓá£
ÒÔÉϾÍÊÇnginxÔõôÆôÓÃstreamµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡