尊龙凯时人生就是博

ÔõÑùʹÓÃNGINXºÍPM2ÓÅ»¯VPSЧÀÍÆ÷µÄϵͳ×ÊÔ´ÖÎÀí

ÔõÑùʹÓÃNGINXºÍPM2ÓÅ»¯VPSЧÀÍÆ÷µÄϵͳ×ÊÔ´ÖÎÀí

Ç°ÑÔ£º

ÔÚÏÖ´úµÄ»¥ÁªÍøÓ¦ÓÃÖУ¬Ð§ÀÍÆ÷ÊdzÐÔØÓªÒµµÄÖ÷Òª»ù´¡ÉèÊ©¡£ÎªÁ˸ü¸ßЧµØʹÓÃЧÀÍÆ÷µÄ×ÊÔ´£¬Ìá¸ßÓ¦ÓõÄÐÔÄܺÍÎȹÌÐÔ£¬ÎÒÃÇ¿ÉÒÔ½ÓÄÉNGINXºÍPM2ÕâÁ½¸ö¹¤¾ßÀ´¾ÙÐÐϵͳ×ÊÔ´µÄÖÎÀíºÍÓÅ»¯¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNGINXºÍPM2À´ÓÅ»¯VPSЧÀÍÆ÷µÄϵͳ×ÊÔ´ÖÎÀí£¬²¢ÌṩһЩÏêϸµÄ´úÂëʾÀý¡£

Ò»¡¢Ê²Ã´ÊÇNGINXºÍPM2

NGINX£¨·¢ÒôΪengine x£©ÊÇÒ»¸ö¸ßÐÔÄܵÄHTTPºÍ·´ÏòÊðÀíЧÀÍÆ÷£¬Ò²¿ÉÒÔÓÃ×÷ÓʼþÊðÀíЧÀÍÆ÷¡£Ëü¾ßÓÐÕ¼ÓÃ×ÊÔ´ÉÙ¡¢¿ìËÙÏìÓ¦¡¢¸ß²¢·¢µÈÓŵ㣬ÆÕ±éÓ¦ÓÃÓڴ¾²Ì¬ÍøÕ¾¡¢¸ºÔØƽºâ¡¢»º´æ¼ÓËٵȡ£

PM2ÊÇÒ»¸öÓÃÓÚÖÎÀíNode.jsÓ¦ÓóÌÐòµÄÀú³ÌÖÎÀíÆ÷¡£Ëü¿ÉÒÔ×ÊÖúÎÒÃÇÖÎÀíºÍ¼à¿ØNode.jsÓ¦ÓóÌÐòµÄÔËÐÐ״̬£¬²¢Ìṩ×Ô¶¯ÖØÆô¡¢¸ºÔØƽºâµÈ¹¦Ð§£¬´Ó¶øÌá¸ßÓ¦ÓõÄÎȹÌÐÔºÍÐÔÄÜ¡£

¶þ¡¢Ê¹ÓÃNGINXºÍPM2ÓÅ»¯VPSЧÀÍÆ÷µÄϵͳ×ÊÔ´ÖÎÀí

×°ÖúÍÉèÖÃNGINX

£¨1£©×°ÖÃNGINX

ÔÚVPSЧÀÍÆ÷ÉÏÖ´ÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃNGINX£º

sudo apt-get update
sudo apt-get install nginx

µÇ¼ºó¸´ÖÆ

£¨2£©ÉèÖÃNGINX

±à¼­/etc/nginx/sites-available/defaultÎļþ£¬½«ÍøÕ¾µÄ¸ùĿ¼ºÍ¶Ë¿ÚºÅÉèÖÃΪÄãµÄÓ¦ÓóÌÐòµÄÏà¹ØÐÅÏ¢£º

server {
    listen 80;
    server_name example.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;
    }
}

µÇ¼ºó¸´ÖÆ

ÉúÑIJ¢Í˳ö¡£

£¨3£©ÖØÆôNGINX

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

sudo service nginx restart

µÇ¼ºó¸´ÖÆ

ʹÓÃPM2ÖÎÀíNode.jsÓ¦ÓóÌÐò

£¨1£©×°ÖÃPM2

ÔÚVPSЧÀÍÆ÷ÉÏÖ´ÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃPM2£º

sudo npm install pm2 -g

µÇ¼ºó¸´ÖÆ

£¨2£©Æô¶¯Ó¦ÓóÌÐò

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

pm2 start app.js

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬app.jsÊÇÄãµÄNode.jsÓ¦ÓóÌÐòµÄÈë¿ÚÎļþ¡£

£¨3£©ÉèÖÃPM2µÄ×Ô¶¯ÖØÆôºÍ¸ºÔØƽºâ

ÔÚÓ¦ÓóÌÐòµÄ¸ùĿ¼Ï½¨ÉèÒ»¸öecosystem.config.jsÎļþ£¬ÄÚÈÝÈçÏ£º

module.exports = {
  apps: [
    {
      name: 'my-app',
      script: 'app.js',
      instances: 'max',
      exec_mode: 'cluster',
      autorestart: true,
      watch: false,
      max_memory_restart: '1G'
    }
  ]
};

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬my-appÊÇÄãµÄÓ¦ÓóÌÐòµÄÃû³Æ£¬app.jsÊÇÄãµÄÓ¦ÓóÌÐòµÄÈë¿ÚÎļþ¡£

ÉúÑIJ¢Í˳ö¡£

£¨4£©Æô¶¯PM2²¢Ó¦ÓÃÉèÖÃ

ÔÚÓ¦ÓóÌÐòµÄ¸ùĿ¼ÏÂÖ´ÐÐÒÔÏÂÏÂÁîÀ´Æô¶¯PM2²¢Ó¦ÓÃÉèÖãº

pm2 start ecosystem.config.js

µÇ¼ºó¸´ÖÆ

Èý¡¢×ܽá

ͨ¹ýʹÓÃNGINXºÍPM2£¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÖÎÀíºÍÓÅ»¯VPSЧÀÍÆ÷µÄϵͳ×ÊÔ´¡£NGINX×÷Ϊ·´ÏòÊðÀíЧÀÍÆ÷£¬¿ÉÒÔÌṩ¸ºÔØƽºâ»ººÍ´æ¼ÓËٵȹ¦Ð§£¬´Ó¶øÌá¸ßЧÀÍÆ÷µÄÐÔÄÜ¡£¶øPM2×÷ΪNode.jsµÄÀú³ÌÖÎÀíÆ÷£¬¿ÉÒÔ×ÊÖúÎÒÃÇÖÎÀíºÍ¼à¿ØNode.jsÓ¦ÓóÌÐò£¬²¢Ìṩ×Ô¶¯ÖØÆôºÍ¸ºÔØƽºâµÈ¹¦Ð§£¬´Ó¶øÌá¸ßÓ¦ÓõÄÎȹÌÐÔºÍÐÔÄÜ¡£

Ï£Íû±¾ÎÄÄܹ»×ÊÖú¶ÁÕ߸üºÃµØÏàʶÔõÑùʹÓÃNGINXºÍPM2ÓÅ»¯VPSЧÀÍÆ÷µÄϵͳ×ÊÔ´ÖÎÀí£¬²¢¸ø³öÁËһЩÏêϸµÄ´úÂëʾÀý£¬¶ÁÕß¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇóºÍÏÖÕæÏàÐξÙÐÐÉèÖú͵÷½â¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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