You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nuxt SSR应用通过Azure部署到IIS仅显示默认Vue页面问题求助

问题原因
  • web.config的iisnode handler配置错误:当前配置中path="server"指向的是目录而非Nuxt SSR的实际入口文件,iisnode无法正确启动Nuxt服务端进程,仅加载了客户端静态资源包,因此出现默认Vue页面、服务端路由全部404的问题。
  • 静态资源重写规则不匹配Nuxt目录结构:配置中静态资源重写目标为public{REQUEST_URI},但Nuxt构建后的客户端静态资源存放于.nuxt/dist/client目录,自定义静态资源存放于static目录,路径不匹配导致资源请求逻辑异常。
  • 动态路由转发规则未正确指向服务入口:所有非静态请求被转发到server目录而非服务入口文件,服务端无法接收到路由请求进行SSR渲染。
解决方案
  1. 修正web.config配置,替换原有内容为适配Nuxt SSR的配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <webSocket enabled="false" />
    <handlers>
      <!-- 指向Nuxt服务端入口文件 -->
      <add name="iisnode" path="server/index.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server/index.js\/debug[\/]?" />
        </rule>
        <!-- 优先匹配.nuxt/dist/client下的构建产物 -->
        <rule name="NuxtClientStatic" stopProcessing="true">
          <match url="^_nuxt/(.*)" />
          <action type="Rewrite" url=".nuxt/dist/client/{R:1}" />
        </rule>
        <!-- 匹配static目录下的静态资源 -->
        <rule name="StaticContent" stopProcessing="true">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="false" />
          </conditions>
          <action type="Rewrite" url="{REQUEST_URI}" />
        </rule>
        <!-- 其余所有请求转发到Nuxt服务端入口 -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
          </conditions>
          <action type="Rewrite" url="server/index.js" />
        </rule>
      </rules>
    </rewrite>
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>
    <httpErrors existingResponse="PassThrough" />
    <!-- 生产环境建议保留node_env="production"配置 -->
    <iisnode node_env="production" watchedFiles="web.config;*.js" />
  </system.webServer>
</configuration>
  1. 确认流水线文件复制逻辑无误,补充检查server/index.js文件已被复制到部署目录,若你使用的Nuxt版本服务入口路径不同,同步修改web.config中的对应路径即可。
  2. 进入服务器部署根目录执行yarn install --production,确保生产环境依赖完整安装。
  3. 重启IIS站点后验证访问即可。

内容的提问来源于stack exchange,提问作者Sun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 01:51:02