NGINX PM2 VPS: ¹¹½¨¸ßÐÔÄܵÄWebЧÀÍÆ÷
NGINX PM2 VPS: ¹¹½¨¸ßÐÔÄܵÄWebЧÀÍÆ÷
½üÄêÀ´£¬Ëæ×Å»¥ÁªÍøµÄÉú³¤£¬WebЧÀÍÆ÷µÄÐÔÄÜÒªÇóÔ½À´Ô½¸ß¡£ÎªÁËÖª×ãÕâЩÐèÇ󣬿ª·¢Ö°Ô±Ò»Ö±Ì½Ë÷еÄÊÖÒպ͹¤¾ß¡£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃNGINX¡¢PM2ºÍVPS¹¹½¨¸ßÐÔÄܵÄWebЧÀÍÆ÷£¬²¢¸½ÉÏÏêϸµÄ´úÂëʾÀý¡£
NGINX
NGINXÊÇÒ»¸ö¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷¡£ËüµÄÉè¼ÆÄ¿µÄÊÇΪÁË´¦Àí´ó×Ú²¢·¢ÅþÁ¬£¬²¢ÇÒ¾ßÓо«²ÊµÄÐÔÄÜ¡£Ïà±ÈÓڹŰåµÄApacheЧÀÍÆ÷£¬NGINXÔ½·¢ÇáÁ¿¼¶£¬²¢ÇÒÄܹ»´¦Àí¸ü¶àµÄ²¢·¢ÇëÇó¡£
ÔÚ×°ÖÃNGINX֮ǰ£¬ÎÒÃÇÐèҪȷ±£VPSÉÏÒѾװÖÃÁËNode.jsºÍnpm¡£¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´×°Öãº
sudo apt update sudo apt install nodejs sudo apt install npm
µÇ¼ºó¸´ÖÆ
×°ÖÃÍêNode.jsºÍnpmÖ®ºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃnpmÀ´×°ÖÃPM2£¬ÕâÊÇÒ»¸öÓÃÓÚÖÎÀíNode.jsÓ¦ÓóÌÐòµÄÀú³ÌÖÎÀíÆ÷¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´¾ÙÐÐ×°Öãº
sudo npm install pm2 -g
µÇ¼ºó¸´ÖÆ
PM2
PM2¿ÉÒÔ×ÊÖúÎÒÃÇÖÎÀíºÍ¼à¿ØNode.jsÓ¦ÓóÌÐò¡£Ëü¿ÉÒÔ×Ô¶¯ÖØÐÂÆô¶¯Ó¦ÓóÌÐò£¬È·±£Ó¦ÓóÌÐòÔÚÍß½âʱÄܹ»¼ÌÐøÔËÐС£±ðµÄ£¬PM2»¹ÌṩÁËÈÕÖ¾¼Í¼ºÍÀú³Ì¼à¿ØµÈ¹¦Ð§¡£
¼ÙÉèÎÒÃÇÒѾÓÐÒ»¸öNode.jsÓ¦ÓóÌÐò£¬²¢ÇÒ¸ÃÓ¦ÓóÌÐòµÄÈë¿ÚÎļþΪapp.js¡£ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîʹÓÃPM2ÔËÐиÃÓ¦ÓóÌÐò£º
pm2 start app.js
µÇ¼ºó¸´ÖÆ
ͨ¹ýÔËÐÐÉÏÊöÏÂÁÎÒÃÇ¿ÉÒÔÈ·±£Node.jsÓ¦ÓóÌÐòÔÚЧÀÍÆ÷Æô¶¯ºó×Ô¶¯ÔËÐУ¬²¢ÇҾ߱¸×Ô¶¯ÖØÆôµÄ¹¦Ð§¡£
NGINXÉèÖ÷´ÏòÊðÀí
ΪÁ˽«ËùÓеÄÇëÇóת·¢¸øNode.jsÓ¦ÓóÌÐò£¬ÎÒÃÇÐèÒªÔÚNGINXÉèÖÃÖÐÌí¼Ó·´ÏòÊðÀí¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒª±à¼NGINXµÄÉèÖÃÎļþ£¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî¾ÙÐб༣º
sudo nano /etc/nginx/nginx.conf
µÇ¼ºó¸´ÖÆ
ÔÚÉèÖÃÎļþÖУ¬ÎÒÃÇÐèÒªÌí¼ÓÒÔÏÂÄÚÈÝ£º
http { server { listen 80; server_name your_domain.com; location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöÉèÖÃÖУ¬ÎÒÃǽ«ËùÓеÄÇëÇó¶¼×ª·¢¸øÍâµØµÄ3000¶Ë¿Ú£¬Ò²¾ÍÊÇÎÒÃÇNode.jsÓ¦ÓóÌÐòÔËÐеĶ˿ڡ£
Íê³ÉÉèÖú󣬿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÖØÆôNGINX£º
sudo service nginx restart
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬ÎÒÃÇÒѾÀֳɵؽ«NGINXÉèÖÃΪ·´ÏòÊðÀí£¬²¢ÇÒ¿ÉÒÔʹÓÃPM2À´ÖÎÀíÎÒÃǵÄNode.jsÓ¦ÓóÌÐòÁË¡£
×ܽá
ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËÔõÑùʹÓÃNGINX¡¢PM2ºÍVPSÀ´¹¹½¨¸ßÐÔÄܵÄWebЧÀÍÆ÷¡£Í¨¹ýʹÓÃNGINX×÷Ϊ·´ÏòÊðÀí£¬¿ÉÒÔ¸üºÃµØÖÎÀí²¢·¢ÅþÁ¬£¬²¢Ìṩ¸üºÃµÄÐÔÄÜ¡£ÁíÍ⣬ͨ¹ýʹÓÃPM2¿ÉÒÔÈ·±£ÎÒÃǵÄNode.jsÓ¦ÓóÌÐòÔÚЧÀÍÆ÷Íß½âºóÄܹ»×Ô¶¯»Ö¸´¡£
Ï£ÍûÕâƪÎÄÕ¶ÔÄãÓÐËù×ÊÖú£¬²¢Äܹ»×ÊÖúÄã¹¹½¨³ö¸ßÐÔÄܵÄWebЧÀÍÆ÷¡£ÈôÊÇÄã¶Ô´úÂëʾÀýÓÐÈκÎÎÊÌâ»òÐèÒª¸ü¶àµÄÖ¸µ¼£¬ÇëËæʱÔÚ̸ÂÛÇøÌáÎÊ¡£
ÒÔÉϾÍÊÇNGINX PM2 VPS: ¹¹½¨¸ßÐÔÄܵÄWebЧÀÍÆ÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡