使用 PHP API 和 APache 服务器在 Digitalocean 上部署 ReactJs 应用程序
Deploy a ReactJs Application on Digitalocean with PHP API and APache server
几天来,我一直在尝试在 Digital Ocean 上部署我的第一个 React JS 应用程序,但没有成功。
它是一个 create react 应用程序,它连接到一个 PHP API 运行 一个 Apache 服务器
我已经使用 npm 运行 build 命令成功构建了我的应用程序。当我尝试从浏览器访问构建文件夹时,我只得到一个空白页面。我通过简单地访问我的浏览器的路由来访问 domain_name.com/myapp/build (仅用于测试目的)来做到这一点。
当我 运行 npm start 时,我可以在 domain.com:3000 以开发模式访问应用程序的主页。我的 package.json 的脚本部分如下所示
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"add-locale": "lingui add-locale",
"flow": "flow",
"start:prod": 'node dist/app.js'
},
我的服务器 运行ning https://domain_name.com but when i do https://domain_name.com:3000,我无法访问我的应用程序的开发版本,但我可以使用 domain_name.com:3000 访问开发版本。
任何有关这些问题的帮助将不胜感激。
当您 运行 npm start 时,您启动 webpack-dev-server 它在 3000 端口上运行并托管您的源代码。
构建 React 应用程序时,您只需准备一个 js 文件,您应该将其与 API 文件一起托管在 Apache 服务器上。
您需要将该 js 文件包含在您的 index.html 结构中,并 <script src="path/to/js">
到该文件。
如果您还有任何问题,请告诉我。
更新:
要解决路由问题,请阅读 the official deployment manual 并搜索 .htaccess
P.S:也许你觉得这个 https://gist.github.com/ywwwtseng/63c36ccb58a25a09f7096bbb602ac1de 有用。
几天来,我一直在尝试在 Digital Ocean 上部署我的第一个 React JS 应用程序,但没有成功。 它是一个 create react 应用程序,它连接到一个 PHP API 运行 一个 Apache 服务器
我已经使用 npm 运行 build 命令成功构建了我的应用程序。当我尝试从浏览器访问构建文件夹时,我只得到一个空白页面。我通过简单地访问我的浏览器的路由来访问 domain_name.com/myapp/build (仅用于测试目的)来做到这一点。
当我 运行 npm start 时,我可以在 domain.com:3000 以开发模式访问应用程序的主页。我的 package.json 的脚本部分如下所示
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"add-locale": "lingui add-locale",
"flow": "flow",
"start:prod": 'node dist/app.js'
},
我的服务器 运行ning https://domain_name.com but when i do https://domain_name.com:3000,我无法访问我的应用程序的开发版本,但我可以使用 domain_name.com:3000 访问开发版本。
任何有关这些问题的帮助将不胜感激。
当您 运行 npm start 时,您启动 webpack-dev-server 它在 3000 端口上运行并托管您的源代码。
构建 React 应用程序时,您只需准备一个 js 文件,您应该将其与 API 文件一起托管在 Apache 服务器上。
您需要将该 js 文件包含在您的 index.html 结构中,并 <script src="path/to/js">
到该文件。
如果您还有任何问题,请告诉我。
更新:
要解决路由问题,请阅读 the official deployment manual 并搜索 .htaccess
P.S:也许你觉得这个 https://gist.github.com/ywwwtseng/63c36ccb58a25a09f7096bbb602ac1de 有用。