問題一:IIS配置導致頁面刷新時找不到文件或目錄
錯誤配置
IIS配置web.config如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="test" patternSyntax="Wildcard">
<match url="*api/*" />
<action type="Rewrite" url="http://10.10.17.74:8085/{R:2}" />
</rule>
</rules>
</rewrite>
<staticContent>
<mimeMap fileExtension=".glb" mimeType="application/glb" />
<clientCache cacheControlMode="DisableCache" cacheControlMaxAge="3.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
問題現象
刷新頁面時提示404找不到文件或目錄。
正確配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="index">
<match url="^((?!(api)).)*$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
<rule name="test" patternSyntax="Wildcard">
<match url="*api/*" />
<action type="Rewrite" url="http://10.10.17.74:8085/{R:2}" />
</rule>
</rules>
</rewrite>
<staticContent>
<mimeMap fileExtension=".glb" mimeType="application/glb" />
<clientCache cacheControlMode="DisableCache" cacheControlMaxAge="3.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
說明:
1、刷新找不到文件或目錄因爲沒有配置
2、mimeMap部分是添加媒體類型後自動追加的
問題二:POST調用後臺請求時報錯405
現象截圖如下
錯誤配置如下
IIS配置web.config如下
<rule name="index">
<match url="^((?!(api)).)*$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
<rule name="dl" patternSyntax="Wildcard">
<match url="*dl/*" />
<action type="Rewrite" url="http://10.10.17.74:9100/{R:2}" />
</rule>
說明
1、配置文件中第一個規則,將所有不包含api的請求捕獲,相當於路由去跳轉。
2、配置文件中第二個規則,將所有包含dl的請求重定向到後臺。
3、然而我現在調用接口/dl/uaa/loginUser,那到底被哪個規則匹配上呢,於是就出問題了。
4、所以需要在調用後臺接口時,所有接口前面都拼上相同的匹配字符串(如api)即可,參考正確配置。
正確配置
<rule name="index">
<match url="^((?!(api)).)*$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
<rule name="dl" patternSyntax="Wildcard">
<match url="*api/dl/*" />
<action type="Rewrite" url="http://10.10.17.74:9100/{R:2}" />
</rule>
其他
通常習慣性使用配置文件直接改寫配置,其實IIS提供界面操作,還可以測試配置的規則是否正確。簡要記錄一下:
1、點擊【URL重寫】
2、即可查看當前網站的URL規則,可添加、修改。
3、雙擊已添加的規則,點擊測試模式,輸入要測試的url,點擊測試後會出現結果,可用於校對重寫URL和捕獲的是否一致。
問題三:添加網站
右鍵-添加網站,其實沒什麼問題,就記錄一下。
問題四:添加媒體類型
本地能看到.glb/.gltf的模型文件,但是放到IIS服務器上就看不到了。
因爲需要配置MIME類型:
然後查看web.config文件發現:
<staticContent>
<mimeMap fileExtension=".glb" mimeType="application/glb" />
<mimeMap fileExtension=".gltf" mimeType="application/gltf" />
<clientCache cacheControlMode="DisableCache" cacheControlMaxAge="3.00:00:00" />
</staticContent>
OK了。