【发布时间】:2018-08-13 13:42:07
【问题描述】:
我在网上搜索了有关如何在 Microsoft 的 IIS 上部署 React 应用程序的解决方案。
我已经成功地部署了多个 Node.JS 应用程序,但 React 却没有这样的运气。
我的尝试:
已安装URL Rewrite
我跑了:
npm i -g create-react-app我创建了一个基本的 React 应用:
create-react-app my-app我在
./public路由中创建了一个名为web.config的文件
web.config
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
- 然后我跑了
npm run build - 在 IIS 中,我添加了一个带有应用程序池的
new website:DefaultAppPool,该路径链接到./build文件夹目录。 - 我跑浏览到应用程序
- 我收到
Site can't be reached错误。
还有其他人尝试在 IIS 上进行部署吗?
我还尝试了以下资源: - https://github.com/react-boilerplate/react-boilerplate/issues/711 - https://www.quora.com/How-can-one-host-ReactJS-in-IIS - https://hackernoon.com/adding-web-config-to-react-projects-3eb762dbe01f
【问题讨论】: