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

½ÌÄãÔõÑùʹÓÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔ

½ÌÄãÔõÑùʹÓÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔ

Ëæ×Å»¥ÁªÍøµÄÆÕ¼°ºÍÊÖÒÕµÄһֱǰ½ø£¬VPSЧÀÍÆ÷ÒѳÉΪÐí¶àÆóÒµºÍ¿ª·¢ÕßÊ×Ñ¡µÄЧÀÍÆ÷½â¾ö¼Æ»®Ö®Ò»¡£¿ÉÊÇ£¬ÔÚÃæÁÙЧÀÍÆ÷¹ÊÕÏ»òÍøÂçÎÊÌâʱ£¬ÔõÑù°ü¹ÜЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔ³ÉΪһ¸öÖ÷ÒªµÄÎÊÌâ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔ£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

NGINXµÄ×°ÖúÍÉèÖÃ

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚVPSЧÀÍÆ÷ÉÏ×°ÖúÍÉèÖÃNGINX¡£ÏÂÃæÊÇÔÚUbuntuϵͳÉÏ×°ÖÃNGINXµÄ°ì·¨£º

1.1 ¸üÐÂϵͳÈí¼þ£ºÖ´ÐÐÒÔÏÂÏÂÁîÀ´¸üÐÂϵͳµÄÈí¼þ°üÁбí¡£

sudo apt update

1.2 ×°ÖÃNGINX£ºÖ´ÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃNGINX¡£

sudo apt install nginx

1.3 ÉèÖÃNGINX£º±à¼­ /etc/nginx/nginx.conf Îļþ£¬ÐÞ¸ÄÆäÖÐµÄ server ²¿·Ö£¬ÈçÏÂËùʾ£º

server {

listen 80;
server_name your_domain.com;

location / {
    proxy_pass http://localhost:3000;
}

µÇ¼ºó¸´ÖÆ

}

ÕâÀォ NGINX ÉèÖÃΪ·´ÏòÊðÀí£¬½«ËùÓеÄÇëÇó¶¼×ª·¢µ½ÍâµØµÄ3000¶Ë¿ÚÉÏ¡£Äã¿ÉÒÔƾ֤ÏÖÕæÏàÐÎÐÞ¸Ä server_name ºÍ proxy_pass µÄÖµ¡£

1.4 ÖØÆôNGINX£ºÖ´ÐÐÒÔÏÂÏÂÁîÀ´ÖØÆôNGINX¡£

sudo service nginx restart

ÖÁ´Ë£¬NGINXµÄ×°ÖúÍÉèÖÃÊÂÇéÍê³É¡£

PM2µÄ×°ÖúÍÉèÖÃ

½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÔÚVPSЧÀÍÆ÷ÉÏ×°ÖúÍÉèÖÃPM2¡£ÏÂÃæÊÇÔÚUbuntuϵͳÉÏ×°ÖÃPM2µÄ°ì·¨£º

2.1 ×°ÖÃPM2£ºÖ´ÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃPM2¡£

sudo npm install -g pm2

2.2 Æô¶¯Ó¦ÓóÌÐò£ºÔÚÏîÄ¿µÄ¸ùĿ¼Ï£¬Ö´ÐÐÒÔÏÂÏÂÁîÀ´Æô¶¯Ó¦ÓóÌÐò¡£

pm2 start app.js

ÕâÀï¼ÙÉèÄãµÄÓ¦ÓóÌÐòµÄÈë¿ÚÎļþÊÇ app.js¡£ÈôÊÇÄãµÄÓ¦ÓóÌÐòʹÓÃÁËÆäËûµÄÈë¿ÚÎļþ£¬ÇëÏìÓ¦µØÐÞ¸ÄÏÂÁî¡£

2.3 ÉèÖÃPM2Æô¶¯¾ç±¾£ºÖ´ÐÐÒÔÏÂÏÂÁîÀ´ÉèÖÃPM2Æô¶¯¾ç±¾¡£

pm2 startup

Õ⽫ÌìÉúÒ»¸öÆô¶¯¾ç±¾£¬Ëü»áÔÚϵͳÆô¶¯Ê±×Ô¶¯Æô¶¯PM2¡£

ÏÖÔÚ£¬PM2µÄ×°ÖúÍÉèÖÃÊÂÇéÍê³É¡£

ʵÏָ߿ÉÓÃÐÔ

ÓÐÁËNGINXºÍPM2µÄ»ù´¡£¬ÎÒÃÇ¿ÉÒÔ×îÏÈʵÏÖVPSЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔÁË¡£ÏÂÃæÊÇÏêϸµÄ°ì·¨£º

3.1 ÉèÖÃPM2µÄÀú³ÌÊýÄ¿£ºÔÚÏîÄ¿µÄ¸ùĿ¼Ï£¬Ö´ÐÐÒÔÏÂÏÂÁîÀ´ÉèÖÃPM2µÄÀú³ÌÊýÄ¿¡£

pm2 scale app.js 3

ÕâÀォӦÓóÌÐòµÄÀú³ÌÊýÄ¿ÉèÖÃΪ3¸ö¡£Äã¿ÉÒÔƾ֤ÏÖʵÐèÇóÉèÖúÏÊʵÄÊýÄ¿¡£

3.2 ÉèÖÃNGINXµÄ¸ºÔØƽºâ£º±à¼­ /etc/nginx/nginx.conf Îļþ£¬ÐÞ¸ÄÆäÖÐµÄ server ²¿·Ö£¬ÈçÏÂËùʾ£º

upstream backend {

server localhost:4000;
server localhost:5000;
server localhost:6000;

µÇ¼ºó¸´ÖÆ

}

server {

listen 80;
server_name your_domain.com;

location / {
    proxy_pass http://backend;
}

µÇ¼ºó¸´ÖÆ

}

ÕâÀォ NGINX ÉèÖÃΪ¸ºÔØƽºâ£¬½«ÇëÇóƽºâµØת·¢µ½Èý¸öÓ¦ÓóÌÐòµÄÀú³ÌÉÏ¡£

3.3 ÖØÆôNGINX£ºÖ´ÐÐÒÔÏÂÏÂÁîÀ´ÖØÆôNGINX¡£

sudo service nginx restart

ÖÁ´Ë£¬VPSЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔÉèÖÃÍê³É¡£

×ܽ᣺

±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔ£¬²¢ÌṩÁËÏêϸµÄ´úÂëʾÀý¡£Í¨¹ýÉèÖÃNGINXµÄ·´ÏòÊðÀíºÍ¸ºÔØƽºâ£¬ÒÔ¼°ÉèÖÃPM2µÄÀú³ÌÊýÄ¿£¬ÎÒÃÇ¿ÉÒÔÈ·±£Ð§ÀÍÆ÷ÔÚÃæÁÙ¹ÊÕÏʱÈÔÄܼá³Ö¸ß¿ÉÓÃÐÔ¡£Ï£Íû±¾ÎĶÔÄãÔÚVPSЧÀÍÆ÷¼Ü¹¹ºÍÉèÖ÷½ÃæÓÐËù×ÊÖú¡£ÈôÊÇÄãÓÐÈκÎÎÊÌ⣬ÇëËæʱÁôÑÔ¡£

ÒÔÉϾÍÊǽÌÄãÔõÑùʹÓÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ