【问题标题】:How to deploy react.js project on iis server at subdomain?如何在子域的 iis 服务器上部署 react.js 项目?
【发布时间】:2019-05-08 23:42:27
【问题描述】:

我想在子域的 iis 服务器上部署 react.js 项目。

我在下面做的工作:

  1. 带有基本名称的BrowserRouter

从 'react-router-dom' 导入 { BrowserRouter };

<BrowserRouter basename="/Subdomain">
   <App></App>
</BrowserRouter>

应用内;

<Switch>
  <Route exact path="/" component={Main} />
...
</Switch>
  1. 在 package.json 中添加“主页”

    “主页”:“https://domain/subdomain/

  2. 为 IIS 安装 URL Rewrite 并创建 web.config

https://www.iis.net/downloads/microsoft/url-rewrite

web.config

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
      <rewrite>
        <rules>
          <rule name="Rewrite Text Requests" stopProcessing="true">
            <match url=".*" />
            <conditions>
              <add input="{HTTP_METHOD}" pattern="^GET$" />
              <add input="{HTTP_ACCEPT}" pattern="^text/html" />
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            </conditions>
            <action type="Rewrite" url="/index.html" />
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
    </configuration>

虽然我做了 iisreset,但在 BrowserRouter 中的链接处打开页面时仍然出现错误(404 - 找不到文件或目录。)。

感谢您的帮助。

【问题讨论】:

  • 你找到解决办法了吗?

标签: reactjs iis url-rewriting web-config webdeploy


【解决方案1】:

在 web.config 的操作中包含您的子域。它有效。

&lt;action type="Rewrite" url="/subdomain/index.html" /&gt;

您可能需要将 web.config 放在您的子域文件夹中。不在根文件夹中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 2019-10-20
    • 2018-08-11
    • 2019-07-29
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多