简体   繁体   English

在 ubuntu 服务器上安装和配置 nodejs 应用程序

[英]Install and configure a nodejs application on a ubuntu server

I am a little lost in this moment.这一刻我有些失落。 It is my first time with nodejs (I have more experience with Php/Apache ).这是我第一次使用nodejs (我对Php/Apache有更多的经验)。 Recently a client gave me access to a bitbucket repository where he had the code of one application on nodejs .最近,一位客户让我访问了一个bitbucket 存储库,他在那里拥有nodejs上一个应用程序的代码。 My final goal is to install that application on a Linux dev server.我的最终目标是在 Linux 开发服务器上安装该应用程序。

Reading a little on the internet, I launch a Ubuntu 16.04 Instance on AWS .在互联网上阅读了一些内容,我在AWS上启动了一个Ubuntu 16.04实例。 I installed Node.js and npm like this:我像这样安装了Node.jsnpm

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
sudo apt-get install python-software-properties python g++ make
sudo apt-get install nodejs-legacy

And if I run these commands, it returns my the versions:如果我运行这些命令,它会返回我的版本:

node --version
v4.4.5
npm --version
2.15.5

So, my question is... now what?所以,我的问题是……现在呢? I have been searching on the internet by a couple hours, and all the tutorials about install node on ubuntu stop right here, but I didn´t find how to configure an app right from the start, and how to install the bitbucket project on my server, and how I made this site accessible by my browser.我已经在互联网上搜索了几个小时,关于在 ubuntu 上安装节点的所有教程都在这里停止,但我没有找到如何从一开始就配置应用程序,以及如何在我的计算机上安装 bitbucket 项目服务器,以及我如何通过浏览器访问该站点。

On a Php/Apache server I must create the project directory con /var/www/ , made a git clone on that directory and configure the site's virtualhost , and access by http://ip_address/ , How I do that in this case?Php/Apache服务器上,我必须创建项目目录 con /var/www/ ,在该目录上进行git clone并配置站点的virtualhost ,并通过http://ip_address/访问,在这种情况下我该怎么做?

I'm sorry, I know maybe these are very basic questions, but really, as I said, I feel lost.对不起,我知道这些可能是非常基本的问题,但真的,正如我所说,我感到迷茫。

If you use express.js for the Webapplication, you first could use pm2 ( https://www.npmjs.com/package/pm2 ) to create a "container" for your application.如果您将 express.js 用于 Web 应用程序,您首先可以使用pm2 ( https://www.npmjs.com/package/pm2 ) 为您的应用程序创建一个“容器”。 If you want to Host your application, I recommend using Nginx with a reverse proxy.如果你想托管你的应用程序,我建议使用带有反向代理的 Nginx。 Here are some Links:以下是一些链接:

  1. https://serverfault.com/questions/601332/how-to-configure-nginx-so-it-works-with-express https://serverfault.com/questions/601332/how-to-configure-nginx-so-it-works-with-express
  2. Nginx Reverse Proxy + ExpressJS + Angular + SSL configuration issues Nginx 反向代理 + ExpressJS + Angular + SSL 配置问题

I hope that helps you.我希望这对你有帮助。 And if you want to install your application, just run npm install in the directory where the package.json is.如果你想安装你的应用程序,只需在package.json所在的目录中运行npm install Maybe you should update node.js because version 4.x is absolutely outdated.也许你应该更新 node.js,因为 4.x 版本已经过时了。

In case you want to manually deploy the app to EC2 and run it yourself, here's what's left to do:如果您想手动将应用程序部署到 EC2 并自行运行,剩下要做的事情如下:

  1. Change your current directory to where you'd like to store the app (I usually use /home/ec2-user , but it doesn't really matter).将当前目录更改为要存储应用程序的位置(我通常使用/home/ec2-user ,但这并不重要)。

  2. Clone the Git repo and cd into it.克隆 Git 存储库并cd到其中。

  3. Install the app's dependencies by running npm install .通过运行npm install应用程序的依赖项。 Note that the app might have additional dependencies you'll have to install manually.请注意,该应用程序可能具有您必须手动安装的其他依赖项。

  4. This step depends on the application itself, but usually you can run a Node.js app by either running npm start (if the start script has been configured in package.json ), or by running node index.js (you can replace index.js with any other file, in case the main file isn't named index.js ).这一步取决于应用程序本身,但通常您可以通过运行npm start (如果start脚本已在package.json配置)或通过运行node index.js (您可以替换node index.js )来运行 Node.js 应用程序index.js与任何其他文件,以防主文件未命名为index.js )。

  5. Now you need to expose the ports the application listens to by modifying the instance's VPC settings.现在,您需要通过修改实例的 VPC 设置来公开应用程序侦听的端口。 More info on how to do this can be found in the official AWS documentation .有关如何执行此操作的更多信息,请参阅 AWS 官方文档

  6. Now you should be able to access your app by going to http://public_ip:port , where public_ip is the public IP address of your EC2 instance (which can be found in the management console (see more on this here ), and port is the port the app is running on.现在您应该可以通过访问http://public_ip:port访问您的应用程序,其中public_ip是您的 EC2 实例的公共 IP 地址(可以在管理控制台中找到(在此处查看更多信息)和port是应用程序运行的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM