0

我正在使用 MongoDB、ExpressJS、ReactJS(create-react-app) 和 NodeJS 构建一个 Web 应用程序。我已经完成了开发部分,现在我想将此 Web 应用程序部署到 Ubuntu 服务器。

我的文件结构如下点击查看图片

package.json (服务器)

{
    "name": "pair-programming",
    "version": "1.0.0",
    "description": "pair-programming web app for codechef's hackathon",
    "main": "server.js",
    "scripts": {
        "client-install": "npm install --prefix client",
        "start": "node server.js",
        "server": "nodemon server.js",
        "client": "npm start --prefix client",
        "dev": "concurrently \"npm run server\" \"npm run client\"",
        "serve-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
    },
    "author": "Parmeet Singh",
    "license": "ISC",
    "dependencies": {
        "bcryptjs": "^2.4.3",
        "body-parser": "^1.18.3",
        "concurrently": "^4.0.1",
        "express": "^4.16.3",
        "jsonwebtoken": "^8.3.0",
        "mongodb": "^3.1.6",
        "mongoose": "^5.2.13",
        "node-uuid": "^1.4.8",
        "nodemailer": "^4.6.8",
        "passport": "^0.4.0",
        "passport-jwt": "^4.0.0",
        "request": "^2.88.0",
        "sprintf-js": "^1.1.1",
        "validator": "^10.7.1"
    },
    "devDependencies": {
        "nodemon": "^1.18.4"
    }
}

package.json(反应)

{
    "name": "client",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "axios": "^0.18.0",
        "classnames": "^2.2.6",
        "jwt-decode": "^2.2.0",
        "react": "^16.5.1",
        "react-dom": "^16.5.1",
        "react-redux": "^5.0.7",
        "react-router-dom": "^4.3.1",
        "react-scripts": "1.1.5",
        "redux": "^4.0.0",
        "redux-thunk": "^2.3.0"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
    },
    "proxy": "http://0.0.0.0:5000"
}

因此,如果可能的话,请帮助我将此 Web 应用程序部署到 ubuntu 服务器。我之前没有在ubuntu上部署过。

4

1 回答 1

0

这很简单,您需要运行几个命令来成功部署您的服务器和反应代码,

假设您没有安装任何 GUI,我们必须使用称为screen

  1. 通过 putty/similar 程序对您的实例进行 ssh。[ssh root@<ipaddress>]
  2. 登录后,您需要输入screen(这将为您提供一个单独的窗口来运行您的命令)
  3. cd到您的服务器目录并运行npm start(这将启动您的服务器代码)
  4. 然后按CTRL-A然后CTRL-D这将分离进程。
  5. 再次输入 screen 然后cd到 react 目录并运行npm start。这将使您的反应应用程序运行。然后分离进程。
  6. 您现在可以注销会话/退出终端。

最后,还要确保打开端口以通过 Internet/Intranet 访问。

于 2018-09-28T13:12:14.733 回答