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

ÔõÑùÉèÖÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ·´ÏòÊðÀí

ÔõÑùÉèÖÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ·´ÏòÊðÀí

ÔÚ¹¹½¨ÍøÂçÓ¦ÓÃʱ£¬·´ÏòÊðÀíÊÇÒ»¸öºÜÊÇÖ÷ÒªµÄ¿´·¨¡£·´ÏòÊðÀíЧÀÍÆ÷¿ÉÒÔ×ÊÖúÎÒÃÇʵÏÖ¸ºÔØƽºâ¡¢¸ß¿ÉÓÃÐÔºÍÇå¾²ÐԵȹ¦Ð§¡£ÔÚVPSЧÀÍÆ÷ÖÐʹÓÃNGINXºÍPM2À´ÉèÖ÷´ÏòÊðÀíÊÇÒ»¸ö·Ç¾­³£¼ûµÄ³¡¾°¡£±¾ÎĽ«ÏêϸÏÈÈÝÔõÑùÉèÖÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ·´ÏòÊðÀí£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

×°ÖÃNGINXºÍPM2

Ê×ÏÈ£¬ÐèÒªÔÚVPSЧÀÍÆ÷ÉÏ×°ÖÃNGINXºÍPM2¡ £¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî×°Öãº

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

# ×°ÖÃPM2
npm install -g pm2

µÇ¼ºó¸´ÖÆ

ÉèÖÃNGINX

NGINXÊÇÒ»¸ö¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷¡£ÉèÖÃNGINXʱ£¬ÐèÒª½¨ÉèÒ»¸öеÄЧÀÍÆ÷¿éÓÃÓÚÊðÀíÇëÇó¡£ÒÔÏÂÊÇÒ»¸öʾÀýµÄNGINXÉèÖÃÎļþ£º

# ·­¿ªÄ¬ÈÏNGINXÉèÖÃÎļþ
sudo nano /etc/nginx/sites-available/default

# ÔÚÎļþÖÐÌí¼ÓÒÔÏÂÉèÖÃ
server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1: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;
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊöʾÀýÖУ¬½«80¶Ë¿ÚµÄÇëÇóÊðÀíµ½ÍâµØµÄ3000¶Ë¿Ú¡£Æ¾Ö¤ÏÖÕæÏàÐÎÐÞ¸Äserver_nameºÍproxy_pass×ֶΡ£

Æô¶¯PM2Ó¦ÓÃ

PM2ÊÇÒ»¸öÓÃÓÚÖÎÀíºÍÊØ»¤Node.jsÓ¦ÓõÄÀú³ÌÖÎÀíÆ÷¡£ÔÚÉèÖÃNGINX֮ǰ£¬ÐèÒªÏÈÆô¶¯PM2Ó¦Óá£ÒÔÏÂÊÇÒ»¸öʾÀýµÄÆô¶¯ÏÂÁ

# Æô¶¯Ó¦ÓÃ
pm2 start app.js

µÇ¼ºó¸´ÖÆ

ƾ֤ÏÖÕæÏàÐÎÌæ»»app.jsΪÏÖʵµÄÓ¦Óþ籾·¾¶¡£

Æô¶¯NGINXºÍPM2

Íê³ÉNGINXºÍPM2µÄÉèÖúó£¬ÐèÒªÆô¶¯ËüÃÇÒÔʹÉèÖÃÉúЧ¡£

# Æô¶¯NGINX
sudo service nginx start

# Æô¶¯PM2
pm2 save
pm2 startup

µÇ¼ºó¸´ÖÆ

ÉèÖ÷À»ðǽ£¨¿ÉÑ¡£©

×îºó£¬»¹¿ÉÒÔÉèÖ÷À»ðǽÒÔÏÞÖƹØÓÚЧÀÍÆ÷µÄ»á¼û¡£ÀýÈ磬ÈôÊÇÖ»ÔÊÐíÌض¨µÄIPµØµã»á¼ûЧÀÍÆ÷£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ

# ÔÊÐíÌض¨IPµØµã»á¼ûЧÀÍÆ÷
sudo ufw allow from your_ip_address to any port 80

µÇ¼ºó¸´ÖÆ

ƾ֤ÏÖÕæÏàÐÎÌæ»»your_ip_addressΪÏÖʵµÄIPµØµã¡£

×ܽá

ͨ¹ýÒÔÉÏ°ì·¨£¬ÎÒÃÇ¿ÉÒÔÉèÖÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ·´ÏòÊðÀí¡£NGINXÈÏÕæÊðÀíÇëÇ󣬽«Æäת·¢µ½ÍâµØµÄNode.jsÓ¦Óá£PM2×÷ΪÀú³ÌÖÎÀíÆ÷£¬ÈÏÕæÆô¶¯ºÍÖÎÀíNode.jsÓ¦Óá£ÕâÑù¿ÉÒÔʵÏÖ¸ºÔØƽºâ¡¢¸ß¿ÉÓÃÐÔºÍÇå¾²ÐԵȹ¦Ð§£¬ÌáÉýÍøÂçÓ¦ÓõÄÐÔÄܺÍÎȹÌÐÔ¡£

Ï£Íû±¾ÎĶÔÄãÃ÷È·ÔõÑùÉèÖÃNGINXºÍPM2ʵÏÖVPSЧÀÍÆ÷µÄ·´ÏòÊðÀíÓÐËù×ÊÖú¡£ÈôÓÐÒÉÎÊ£¬ÇëËæʱÁôÑÔ¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ