尊龙凯时人生就是搏

NGINXºÍPM2: ÌáÉýVPSЧÀÍÆ÷µÄÐÔÄܺÍÎȹÌÐÔ

NGINXºÍPM2: ÌáÉýVPSЧÀÍÆ÷µÄÐÔÄܺÍÎȹÌÐÔ£¬ÐèÒªÏêϸ´úÂëʾÀý

СÐò£º

ÏÖ´ú»¥ÁªÍøʱ´ú£¬Ð§ÀÍÆ÷µÄÐÔÄܺÍÎȹÌÐÔ¹ØÓÚÍøÕ¾µÄÕý³£ÔËÐÐÖÁ¹ØÖ÷Òª¡£ÔÚ´¦Àí¸ß²¢·¢ÇëÇóʱ£¬Ð§ÀÍÆ÷µÄÐÔÄܺÍÎȹÌÐÔÖ±½ÓÓ°ÏìÓû§ÌåÑ顣ΪÁËÌáÉýЧÀÍÆ÷µÄÐÔÄܺÍÎȹÌÐÔ£¬NGINXºÍPM2ÊÇÁ½¸öºÜÊÇÓÐÓõŤ¾ß¡£NGINXÊÇÒ»¸ö¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷£¬PM2ÊÇÒ»¸öÀú³ÌÖÎÀí¹¤¾ß¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNGINXºÍPM2À´ÌáÉýVPSЧÀÍÆ÷µÄÐÔÄܺÍÎȹÌÐÔ£¬²¢¸ø³öһЩÏêϸµÄ´úÂëʾÀý¡£

Ò»¡¢×°ÖúÍÉèÖÃNGINX

×°ÖÃNGINX

ÔÚVPSЧÀÍÆ÷ÉÏ×°ÖÃNGINXºÜÊǼòÆÓ¡£Ê×ÏÈ£¬¸üÐÂЧÀÍÆ÷µÄÈí¼þ°üÁбí£¬È»ºóʹÓÃapt-getÏÂÁî×°ÖÃNGINX¡£

sudo apt-get update
sudo apt-get install nginx

µÇ¼ºó¸´ÖÆ

ÉèÖÃNGINX

×°ÖÃÍê³Éºó£¬ÐèÒª¶ÔNGINX¾ÙÐÐһЩ»ù±¾ÉèÖá£Ö÷Òª°üÀ¨ÐÞ¸ÄNGINXĬÈÏÉèÖÃÎļþºÍ½¨ÉèÐéÄâÖ÷»úÉèÖÃÎļþ¡£

ÐÞ¸ÄĬÈÏÉèÖÃÎļþ

ĬÈÏÉèÖÃÎļþλÓÚ/etc/nginx/nginx.conf¡ £¿ÉÒÔʹÓÃÈκÎÎı¾±à¼­Æ÷·­¿ª²¢Ð޸ġ£Æ¾Ö¤Ð§ÀÍÆ÷Ó²¼þµÄÉèÖ㬿ÉÒÔÐÞ¸ÄһЩ²ÎÊý£¬Èçworker_processesºÍworker_connectionsµÈ£¬ÒÔÓÅ»¯NGINXÐÔÄÜ¡£

½¨ÉèÐéÄâÖ÷»úÉèÖÃÎļþ

ÐéÄâÖ÷»úÉèÖÃÎļþλÓÚ/etc/nginx/sites-available/Ŀ¼ÖС £¿ÉÒÔ½¨ÉèÒ»¸öеÄÉèÖÃÎļþÀ´ÎªÃ¿¸öÍøÕ¾½¨ÉèÒ»¸ö×ÔÁ¦µÄÐéÄâÖ÷»ú¡£ÒÔÏÂÊÇÒ»¸öʾÀýµÄÐéÄâÖ÷»úÉèÖÃÎļþ£º

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

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÒÔÉÏʾÀýÉèÖÃÁËÒ»¸ö»ù±¾µÄ·´ÏòÊðÀíЧÀÍÆ÷£¬Î´À´×Ôexample.comµÄÇëÇóת·¢µ½ÍâµØµÄ¶Ë¿Ú3000ÉÏ¡£

Æô¶¯NGINX²¢ÑéÖ¤ÉèÖÃ

Íê³ÉÉèÖúó£¬ÐèÒªÆô¶¯NGINX£¬²¢Ê¹ÓÃä¯ÀÀÆ÷ÑéÖ¤ÉèÖÃÊÇ·ñÉúЧ¡£

sudo service nginx start

µÇ¼ºó¸´ÖÆ

·­¿ªä¯ÀÀÆ÷£¬»á¼ûÉèÖõÄÓòÃû»òIPµØµã£¬ÈôÊÇÒ»ÇÐÕý³££¬½«»á¿´µ½NGINXµÄĬÈϽӴýÒ³Ãæ¡£

¶þ¡¢×°ÖúÍÉèÖÃPM2

×°ÖÃPM2

ʹÓÃnpmÈ«¾Ö×°ÖÃPM2ºÜÊǼòÆÓ¡£

sudo npm install -g pm2

µÇ¼ºó¸´ÖÆ

Æô¶¯ºÍÖÎÀíÓ¦ÓóÌÐò

ʹÓÃPM2Æô¶¯ºÍÖÎÀíÓ¦ÓóÌÐòºÜÊÇÀû±ã¡£ÔÚÏîÄ¿µÄ¸ùĿ¼Ï£¬Ê¹ÓÃÒÔÏÂÏÂÁîÆô¶¯Ó¦ÓóÌÐò£º

pm2 start app.js

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÄúÒ²¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¶ÔÓ¦ÓóÌÐò¾ÙÐÐÆäËû²Ù×÷£º

Éó²éÓ¦ÓóÌÐòÁбí

pm2 list

µÇ¼ºó¸´ÖÆ

×èÖ¹Ó¦ÓóÌÐò

pm2 stop app

µÇ¼ºó¸´ÖÆ

ÖØÐÂÆô¶¯Ó¦ÓóÌÐò

pm2 restart app

µÇ¼ºó¸´ÖÆ

Èý¡¢NGINXºÍPM2µÄÍŽáʹÓÃ

ÉèÖÃNGINX·´ÏòÊðÀí

ÔÚNGINXµÄÐéÄâÖ÷»úÉèÖÃÎļþÖУ¬½«HTTPÇëÇóת·¢ÖÁPM2ÔËÐеÄÓ¦ÓóÌÐò¡£

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

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

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

ÔÚÏîÄ¿µÄ¸ùĿ¼Ï£¬Ê¹ÓÃPM2Æô¶¯Ó¦ÓóÌÐò¡£

pm2 start app.js

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÒÔÉϽ«Æô¶¯Ò»¸öNode.jsÓ¦ÓóÌÐò£¬¼àÌý3000¶Ë¿Ú¡£

²âÊÔºÍÑéÖ¤

ͨ¹ýÒÔÉÏÉèÖúÍÆô¶¯£¬NGINXÎüÊÕµ½µÄHTTPÇëÇ󽫻ᱻת·¢ÖÁPM2ÔËÐеÄÓ¦ÓóÌÐò¡£·­¿ªä¯ÀÀÆ÷£¬»á¼ûÉèÖõÄÓòÃû»òIPµØµã£¬ÈôÊÇÒ»ÇÐÕý³££¬½«»á¿´µ½Ó¦ÓóÌÐòµÄÒ³Ãæ¡£

½áÂÛ£º

ͨ¹ýÍŽáʹÓÃNGINXºÍPM2£¬ÎÒÃÇ¿ÉÒÔÌáÉýVPSЧÀÍÆ÷µÄÐÔÄܺÍÎȹÌÐÔ¡£Ê¹ÓÃNGINX×÷Ϊ·´ÏòÊðÀíЧÀÍÆ÷¿ÉÒÔÌá¸ß²¢·¢ÇëÇóµÄ´¦ÀíÄÜÁ¦£¬Ê¹ÓÃPM2¿ÉÒÔÀû±ãµØÖÎÀíÓ¦ÓóÌÐòµÄÆô¶¯ºÍ¼à¿Ø¡£Ï£Íû±¾ÎĵĴúÂëʾÀý¹ØÓÚʹÓÃNGINXºÍPM2ÌáÉýЧÀÍÆ÷ÐÔÄܺÍÎȹÌÐԵĶÁÕßÃÇÓÐËù×ÊÖú¡£

×Ü×ÖÊý£º634×Ö

ÒÔÉϾÍÊÇNGINXºÍPM2: ÌáÉýVPSЧÀÍÆ÷µÄÐÔÄܺÍÎȹÌÐÔµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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