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

React Native for Web应用部署至Azure环境的目标目录咨询

问题解决:React Native for Web部署至Azure Web App后仍显示默认Python页面

你的文件上传目录wwwroot是正确的,问题出在Azure Web App的运行时配置和静态文件路由设置上,以下是解决步骤:

  • 切换运行时堆栈
    登录Azure门户,进入你的Web App,依次点击设置 -> 配置 -> 常规设置,将运行时堆栈修改为Static HTML(推荐,适合静态单页应用)或对应版本的Node.js,保存后重启Web App。

  • 添加静态路由配置文件
    如果使用Windows主机,在wwwroot目录下创建web.config文件,内容如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="React Routes" 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>
      </system.webServer>
    </configuration>
    

    如果是Linux主机,在wwwroot目录下创建.htaccess文件,内容如下:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L]
    
  • 确认文件结构
    确保本地web-build文件夹内的所有文件(如index.html、static文件夹等)直接上传至wwwroot根目录,不要嵌套在wwwroot/web-build子目录中。

完成以上操作后,重启Web App,再次访问站点即可正常加载你的React Native for Web应用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 20:56:06