反应:如何使用React-starter-kit在服务器上发布页面

所以,我使用repo创build了一个页面: https : //github.com/kriasoft/react-starter-kit

我有我自己的全球ftp服务器。 现在我想在服务器上发布我的项目。

什么是最好的方法来做到这一点。 我应该复制所有文件到FTP服务器,只需执行命令“NPM开始”? 或者,也许我应该部署它?

我是networking部署新手,不知道它是如何工作的。

感谢您的任何提示。

这是一个很大的话题,无论你的Linux发行版是什么,你可能总是需要2台服务器 – 代理服务器和应用服务器。

我build议你用一个简单的Node.js服务器(如Express或Hapi)来包装你编译的网站。 然后configurationnginx将所有请求正确路由到应用程序。 查看DigitalOcean的一些详细指南

  1. CentOS: https : //www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-centos-7
  2. Ubuntu: https : //www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04

小步骤可能会略有不同,但你明白了

这可能是一个更复杂的东西,而不是只是你的项目。 以下是我用于在digitalocean上设置服务器的说明。

sudo apt-get update sudo apt-get install npm sudo apt-get install git sudo apt-get install ufw sudo apt-get install build-essential libssl-dev curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash nvm install stable //may require new ssh session before this ufw default deny incoming ufw default allow outgoing ufw allow ssh ufw allow 80/tcp ufw allow out to any port 53 ufw enable sudo npm install -g forever sudo npm install -g node-gyp cd /var mkdir www cd www git clone https://github.com/calitek/palminfo --recursive npm install npm ls -depth 0 export PORT=80 node js/server.js test using ip / when good exit then forever start js/server.js set dns 

一种方法是在服务器上构build应用程序,但是您将需要像Heroku那样的已经决定使用的东西。

但是替代scheme是做一个范式转变。 你的应用程序基本上只是一些html,css和javascript,这是编译和公开的。 你可以使用npm run build自己编译,然后把编译好的文件复制到你的托pipe服务器上,这个服务器可以使用它所需要的服务器:apache httpd,nginx等。这也比较便宜,因为你只需要基本托pipe,而不是一些复杂nodejs编译服务器。

我创build了一个入门工具包http://redux-minimal.js.org/ ,它可以帮助您用最less的软件包和非常简单的configuration设置创build丰富的真实世界的应用程序。 如果您查看文件夹结构,您可以看到应用程序使用公用文件夹中的index.html,然后直接在公用文件夹中编译css和js文件。 这使得将公用文件夹复制到您想要的任何服务器上变得更容易。