IIS 10上的create-react-app [英] create-react-app on IIS 10

查看:184
本文介绍了IIS 10上的create-react-app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了有关如何在Microsoft IIS上部署React App的解决方案的信息.

I've scoured the web searching for a solution on how to deploy a React App on Microsoft's IIS.

我已经成功地部署了多个Node.JS应用程序,但是React却没有运气.

I have successfully managed to deploy multiple Node.JS Applications but no such luck with React.

我尝试过的事情:

  1. 已安装 URL重写

我跑了:npm i -g create-react-app

我创建了一个基本的React应用:create-react-app my-app

I created a basic react app: create-react-app my-app

我在./public路线中创建了一个名为web.config的文件

I created a file called web.config in ./public route

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>

  1. 然后我跑了npm run build
  2. 在IIS中,我添加了带有应用程序池DefaultAppPoolnew website,该路径链接到./build文件夹目录.
  3. 我已经浏览到应用程序
  4. 我收到Site can't be reached错误.
  1. I then ran npm run build
  2. In IIS I added a new website with Application Pool: DefaultAppPool, the path linked to the ./build folder directory.
  3. I ran browsed to the App
  4. I get a Site can't be reached Error.

还有其他人试图在IIS上进行部署吗?

Anyone else tried to deploy on IIS?

我还尝试了以下资源: - https://github.com/react-boilerplate/react-boilerplate/issues/711 - https://www.quora.com/How-can- IIS中的一台主机ReactJS - https://hackernoon.com/adding-web-config-to- react-projects-3eb762dbe01f

I've also tried the following resources: - 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

推荐答案

我刚刚尝试了一下,并且有效:

I just tried this and it worked:

create-react-app myapp

create-react-app myapp

构建纱线(或npm)

  • 打开IIS管理器并创建一个新网站
  • 将其指向新创建的react项目中的构建文件夹
  • 创建一个新的应用程序池
  • 右键单击应用程序池,然后在流程模型"下找到身份",单击三个点
  • 选择自定义并输入Windows凭据.

如果这不起作用,则可能需要启用对文件的读/写访问,因此右键单击网站并选择编辑权限

If this doesnt work you may need to enable read/write access to the files so right click on the website and select edit permissions

  • 转到安全性"并点击编辑", 选择经过身份验证的用户,然后在对话框底部,在适当的地方选中修改/完全控制/读/写框.对应该在组或用户名"部分下列出的Windows用户执行相同的操作.点击应用/保存".

  • Go to Security and hit edit, select Authenticated Users and on the bottom of the dialog check the modify/full control /read/write boxes where applicable. Do the same for your windows user that should be listed under Groups or user names section. Hit apply/save.

右键单击该网站,然后转到管理网站",然后浏览.

Right click the website and go to Manage Website then browse.

景气.

这篇关于IIS 10上的create-react-app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆