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

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ЧÀÍÆ÷µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ