首页 > 解决方案 > 在默认网站下将 Vue 应用程序部署到 IIS

问题描述

我成功地让 Vue 应用程序在 iis 的根级别使用端口(8181)工作,但我需要让它在 iis 的默认网站下工作(端口 80)

为了测试这一点,我使用 Vs19 模板创建了一个全新的网站。(应该使用vue脚手架,明天会尝试,完成,重现相同的错误)

在 npm run serve 下启动并运行它。

跑 npm run build

转到 IIS,在 Default Web Site 下添加了一个名为 VuejsApp2 的新应用程序,指向主文件夹下的 dist 文件夹。

复制了 vue 应用的默认 web.config:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
      <system.webServer>
          <rewrite>
              <rules>
                  <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
                      <match url="(.*)" />
                      <conditions logicalGrouping="MatchAll">
                          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                      </conditions>
                      <action type="Rewrite" url="/" />
                  </rule>
              </rules>
          </rewrite>
          <httpErrors>
              <remove statusCode="404" subStatusCode="-1" />
              <remove statusCode="500" subStatusCode="-1" />
              <error statusCode="404" path="/survey/notfound" responseMode="ExecuteURL" />
              <error statusCode="500" path="/survey/error" responseMode="ExecuteURL" />
          </httpErrors>
          <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
  </configuration>

文件夹

转到 Dist 文件夹并设置安全用户“Everyone”并授予它对该文件夹的完全访问权限(是的,我知道,这是一个测试)

通过查看已安装的应用程序,确保已安装 URl 重写(需要让应用程序在基础上运行)

应用程序和功能中安装的应用程序的图像

将 IIS 中的应用程序指向与其他应用程序相同的应用程序池(集成,否 iis 设置

当我在 http://localhost/VuejsApp2 导航到 chrome 中的应用程序时

我收到 503 服务不可用错误

在此处输入图像描述

我认为这是基本的东西,但是我发现所有在 iis 中托管 vue 的教程,这就是列出要做的所有事情,我发现了一个关于同一主题的 SO 问题,但它没有答案......

其他没有答案的SO问题

我读到 IIS 中的 503 意味着应用程序池由于多次崩溃而停止,但应用程序池显示启动并没有停止。

更新:

我将此添加到我的基本空 vue 应用程序的 web.config 中,但仍然出现 503 错误

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
      <system.webServer>
          <rewrite>
              <rules>
                  <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
                      <match url="(.*)" />
                      <conditions logicalGrouping="MatchAll">
                          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                      </conditions>
                      <action type="Rewrite" url="/index.html" />
                  </rule>
              </rules>
          </rewrite>
          <httpErrors>
              <remove statusCode="404" subStatusCode="-1" />
              <remove statusCode="500" subStatusCode="-1" />
              <error statusCode="404" path="/survey/notfound" responseMode="ExecuteURL" />
              <error statusCode="500" path="/survey/error" responseMode="ExecuteURL" />
          </httpErrors>
          <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
  </configuration>

在我原来的应用程序上,我做到了,但我得到了一个不同的不相关错误。所以也许它有帮助?

标签: vue.jsiisvuejs2windows-10

解决方案


我会检查您的重写规则,我认为由于重定向太多而导致错误。

您将任何打算被 VueRouter 拾取的东西发送到您网站的根目录,而不是发送到您的 index.html。将您的重写规则更改为此

 <action type="Rewrite" url="/index.html" />

我认为这可能有助于解决您的问题


推荐阅读