我正在使用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 (react(
{
"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"
}
因此,如果可能的话,请帮助我将这个网络应用程序部署到 ubuntu 服务器。我以前没有在 ubuntu 上部署过。
这很简单,您需要运行几个命令来成功部署服务器和反应代码,
假设您没有安装任何 GUI,我们必须使用称为screen
- 通过 putty/类似程序 SSH 您的实例。[SSH root@
] - 登录后,您需要键入
screen
(这将为您提供一个单独的窗口来运行命令( cd
到你的服务器目录并运行npm start
(这将启动你的服务器代码(- 然后按
CTRL-A
然后CTRL-D
这将分离该过程。 - 再次键入 screen,然后
cd
到 react 目录并运行npm start
。这将使您的反应应用程序运行。然后分离该过程。 - 您可以立即注销会话/退出终端。
最后,还要确保端口已打开,以便通过互联网/内联网进行访问。