vue.js - 在默认网站下将 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 中的应用程序指向与其他应用程序相同的应用程序池(集成,否
当我在 http://localhost/VuejsApp2 导航到 chrome 中的应用程序时
我收到 503 服务不可用错误
我认为这是基本的东西,但是我发现所有在 iis 中托管 vue 的教程,这就是列出要做的所有事情,我发现了一个关于同一主题的 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>
在我原来的应用程序上,我做到了,但我得到了一个不同的不相关错误。所以也许它有帮助?
解决方案
我会检查您的重写规则,我认为由于重定向太多而导致错误。
您将任何打算被 VueRouter 拾取的东西发送到您网站的根目录,而不是发送到您的 index.html。将您的重写规则更改为此
<action type="Rewrite" url="/index.html" />
我认为这可能有助于解决您的问题
推荐阅读
- c - C中的字符串如何分配指向char的指针?
- python - 是否可以使用 camelot 仅从 pdf 中提取表格?它应该只检测表格而不是文本
- r - R igraph:在 igraph 中寻找最短路径,为其添加权重并寻找替代路径
- ios - 登录后,实现 Auth0 的 Django 应用程序不会在 iOS 设备上呈现
- javascript - 如何在双击时关闭 Bootstrap Datepicker?
- azure-cosmosdb - Azure Cosmos DB Emulator 未运行除 SQL API 之外的任何 API
- mysql - 如何将 Oracle 存储过程转换为 MySQL
- docker - 如何解决错误:ErrorCode 22 The requested URL returned error: 502 Bad Gateway" 在 Docker 中运行 Gitlab Image 时?
- python-3.x - pd.read_csv 产生 HTTPError: HTTP Error 403: Forbidden
- python - 移除背景