尊龙凯时人生就是搏

ÔõÑùʹÓÃNGINXºÍPM2ÉèÖÃVPSЧÀÍÆ÷

ÔõÑùʹÓÃNGINXºÍPM2ÉèÖÃVPSЧÀÍÆ÷

ÔڴWebЧÀÍÆ÷µÄÀú³ÌÖÐ £¬Ê¹ÓÃNGINXºÍPM2ÊÇÒ»ÖÖ³£¼ûµÄÉèÖ÷½·¨¡£NGINXÊÇÒ»¿î¸ßÐÔÄܵÄWebЧÀÍÆ÷ £¬³£ÓÃÓÚ·´ÏòÊðÀíºÍ¸ºÔØƽºâ¡£¶øPM2ÊÇÒ»¸öÀú³ÌÖÎÀí¹¤¾ß £¬¿ÉÔÚЧÀÍÆ÷ÉÏÔËÐкÍÖÎÀíNode.jsÓ¦ÓóÌÐò¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNGINXºÍPM2ÉèÖÃVPSЧÀÍÆ÷ £¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

µÚÒ»²½£º×°ÖÃNGINXºÍPM2

Ê×ÏÈ £¬µÇ¼µ½VPSЧÀÍÆ÷ £¬ÔËÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃNGINXºÍPM2£º

# ×°ÖÃNGINX
sudo apt-get update
sudo apt-get install nginx

# ×°ÖÃNode.jsºÍPM2
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install -g pm2

µÇ¼ºó¸´ÖÆ

µÚ¶þ²½£ºÉèÖÃNGINX

ÉèÖÃNGINXµÄÖ÷ҪĿµÄÊǽ«HTTPÁ÷Á¿µ¼Ïòµ½×¼È·µÄ¶Ë¿ÚºÍÓ¦ÓóÌÐò¡£ÔÚЧÀÍÆ÷ÉϽ¨ÉèÒ»¸öNGINXÉèÖÃÎļþ£º

sudo nano /etc/nginx/sites-available/default

µÇ¼ºó¸´ÖÆ

ÔÚ·­¿ªµÄÎļþÖÐ £¬½«ÒÔÏÂÄÚÈÝÕ³Ìùµ½ÆäÖУº

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;
  }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊöÉèÖÃÖÐ £¬½«”your_domain.com”Ì滻ΪÄãµÄÓòÃû»òЧÀÍÆ÷µÄIPµØµã £¬²¢½«”localhost:3000″Ì滻ΪÄãÓ¦ÓóÌÐòÔËÐеĶ˿Ú¡£

ÉúÑIJ¢¹Ø±ÕÎļþºó £¬ÖØÐÂÆô¶¯NGINXЧÀÍ£º

sudo service nginx restart

µÇ¼ºó¸´ÖÆ

µÚÈý²½£ºÉèÖÃPM2

ʹÓÃPM2À´ÔËÐкÍÖÎÀíNode.jsÓ¦ÓóÌÐòºÜÊǼòÆÓ¡£ÔÚÄãµÄÓ¦ÓóÌÐòĿ¼Ï £¬Ê¹ÓÃÒÔÏÂÏÂÁîÆô¶¯Ó¦ÓóÌÐò£º

pm2 start app.js --name my-app

µÇ¼ºó¸´ÖÆ

ÉÏÊöÏÂÁÆô¶¯Ò»¸öÃûΪ”my-app”µÄÀú³Ì £¬²¢½«Ó¦ÓóÌÐòµÄÈë¿ÚÎļþÉèΪ”app.js”¡£Äã¿ÉÒÔƾ֤×Ô¼ºµÄÓ¦ÓóÌÐò¾ÙÐÐÊʵ±µÄÌæ»»¡£

ÈôÊÇÄãµÄÓ¦ÓóÌÐòÐèҪʹÓÃÇéÐαäÁ¿ £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Ö¸¶¨ÇéÐαäÁ¿£º

pm2 start app.js --name my-app --env production

µÇ¼ºó¸´ÖÆ

ÈôÊÇÄãµÄÓ¦ÓóÌÐòÐèÒªÖ¸¶¨ÊÂÇéĿ¼ £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Æô¶¯Ó¦ÓóÌÐò£º

pm2 start app.js --name my-app --cwd /path/to/app

µÇ¼ºó¸´ÖÆ

ʹÓÃPM2Æô¶¯Ó¦ÓóÌÐòºó £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Éó²éÄ¿½ñÔËÐеÄÓ¦ÓóÌÐò£º

pm2 list

µÇ¼ºó¸´ÖÆ

ÈôÊÇÄãÏëÒªÖØÐÂÆô¶¯»ò×èÖ¹Ó¦ÓóÌÐò £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ

pm2 restart my-app
pm2 stop my-app

µÇ¼ºó¸´ÖÆ

×îºó £¬ÈôÊÇÄãÏ£ÍûÔÚЧÀÍÖØÊÓÆôºó×Ô¶¯Æô¶¯Ó¦ÓóÌÐò £¬¿ÉÒÔÔËÐÐÒÔÏÂÏÂÁ

pm2 startup

µÇ¼ºó¸´ÖÆ

PM2½«ÌìÉúÒ»¸öÏÂÁî £¬²¢½«Æ临ÖƵ½ÖÕ¶ËÖÐÔËÐС£´ËÏÂÁÔÚЧÀÍÆ÷Æô¶¯Ê±×Ô¶¯Æô¶¯PM2ºÍÄãµÄÓ¦ÓóÌÐò¡£

×ܽá

ͨ¹ýÒÔÉÏ°ì·¨ £¬ÄãÒÑÀÖ³ÉʹÓÃNGINXºÍPM2ÉèÖÃÁËVPSЧÀÍÆ÷¡£NGINX½«ÈÏÕ潫HTTPÁ÷Á¿µ¼Ïòµ½×¼È·µÄ¶Ë¿ÚºÍÓ¦ÓóÌÐò £¬¶øPM2½«ÔÚЧÀÍÆ÷ÉÏÔËÐкÍÖÎÀíÄãµÄNode.jsÓ¦ÓóÌÐò¡£Ê¹ÓÃNGINXºÍPM2 £¬¿ÉÒÔʵÏÖ¸ßÐÔÄܺÍÎȹÌÐÔµÄWebЧÀÍÆ÷¡£

Ï£ÍûÕâƪÎÄÕ¶ÔÄãÓÐËù×ÊÖú£¡

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

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ