×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùʵÏÖNginxµÄTCP/UDPÊðÀíÉèÖÃ

NginxÊÇÒ»¸ö¹¦Ð§Ç¿Ê¢µÄWebЧÀÍÆ÷Èí¼þ£¬²»µ«¿ÉÒÔ´¦ÀíHTTP/HTTPSЭÒéµÄÇëÇó£¬Ò²¿ÉÒÔͨ¹ýTCP/UDPÊðÀíʵÏÖÆäËûЭÒéµÄת·¢¡£

ÏÂÃ棬ÎÒÃǽ«ÏÈÈÝÔõÑùͨ¹ýNginxʵÏÖTCP/UDPÊðÀíÉèÖ㬲¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

ÉèÖÃTCPÊðÀí

Ê×ÏÈ£¬ÔÚNginxµÄÉèÖÃÎļþÖÐÌí¼ÓÒÔÏ´úÂ룺

stream {
    server {
        listen        80;
        proxy_pass    backend:8080;
    }
}

µÇ¼ºó¸´ÖÆ

Õâ¶ÎÉèÖÃʵÏÖÁ˽«ËùÓÐ80¶Ë¿ÚµÄTCPÇëÇóת·¢µ½backendÖ÷»úµÄ8080¶Ë¿ÚÉÏ¡£ÐèҪעÖصÄÊÇ£¬backend¿ÉÒÔÊÇÒ»¸öIPµØµã£¬Ò²¿ÉÒÔÊÇNginxÉèÖÃÎļþÖÐÆäËûserverµÄÃû³Æ¡£

±ðµÄ£¬ÎªÁËÈÃNginx¼àÌýTCPÇëÇ󣬻¹ÐèÒªÔÚÆô¶¯NginxµÄÏÂÁîÖÐÌí¼Ó-g ‘daemon off;’Ñ¡Ïî¡£ÍêÕûµÄÆô¶¯ÏÂÁîÈçÏ£º

nginx -g 'daemon off;'

µÇ¼ºó¸´ÖÆ

ÉèÖÃUDPÊðÀí

Õë¶ÔUDPÊðÀí£¬NginxÐèҪʹÓõÚÈý·½Ä  £¿éStream Module¡£ÐèÒªÔÚ±àÒëNginxʱÌí¼Ó–with-streamÑ¡Ï²¢ÔÚNginxµÄÉèÖÃÎļþÖÐÌí¼ÓÒÔÏ´úÂ룺

stream {
    server {
        listen          53 udp;
        proxy_pass      backend:53;
        proxy_timeout   1s;
        proxy_responses 1;
    }
}

µÇ¼ºó¸´ÖÆ

Õâ¶ÎÉèÖÃʵÏÖÁ˽«ËùÓÐUDPµÄ53¶Ë¿ÚµÄÇëÇóת·¢µ½backendÖ÷»úµÄ53¶Ë¿ÚÉÏ£¬Í¬Ê±ÉèÖÃÁË1ÃëµÄ³¬Ê±Ê±¼äºÍ×î¶à·µ»ØÒ»¸öÏìӦЧ¹û¡£

ÐèҪעÖصÄÊÇ£¬ÔÚÒÔÉÏÉèÖÃÖУ¬backend¿ÉÒÔÊÇÒ»¸öIPµØµã£¬Ò²¿ÉÒÔÊÇNginxÉèÖÃÎļþÖÐÆäËûserverµÄÃû³Æ¡£

ÍêÕûʾÀý

×îÖÕ£¬ÎÒÃÇÌṩһ¸öÍêÕûµÄTCPºÍUDPÊðÀíÉèÖÃʾÀý£¬´úÂëÈçÏ£º

events {}

http {}

stream {
    server {
        listen        80;
        proxy_pass    backend:8080;
    }

    server {
        listen          53 udp;
        proxy_pass      backend:53;
        proxy_timeout   1s;
        proxy_responses 1;
    }
}

µÇ¼ºó¸´ÖÆ

ÐèҪעÖصÄÊÇ£¬ÒÔÉÏʾÀýÖеÄbackend¿ÉÒÔÊÇÒ»¸öIPµØµã£¬Ò²¿ÉÒÔÊÇNginxÉèÖÃÎļþÖÐÆäËûserverµÄÃû³Æ¡£

×ܽá

ͨ¹ýÒÔÉÏʾÀý´úÂ룬ÎÒÃÇÏàʶÁËÔõÑùÔÚNginxÖÐʵÏÖTCP/UDPÊðÀíÉèÖã¬Éæ¼°µÄÒªº¦µã°üÀ¨Ê¹ÓÃStream ModuleÄ  £¿é¡¢Ìí¼ÓlistenºÍproxy_passµÈÒªº¦×ֵȡ£Ï£ÍûÕâƪÎÄÕÂÄÜΪ¸÷ÈËʵÏÖNginxÊðÀíÉèÖÃÌṩһЩ×ÊÖú£¡

ÒÔÉϾÍÊÇÔõÑùʵÏÖNginxµÄTCP/UDPÊðÀíÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ