繁体   English   中英

在IIS8 Windows服务器(Azure VM)上部署React App

[英]Deploying React App on IIS8 Windows server (Azure VM)

请帮忙。 我有一个反应应用程序,从VS2017发布时完美运行。 托管在Azure VM(IIS-8,Windows Server)上的相同应用程序给出了404或500错误。

我的托管目录结构适用于我的.Net应用程序和混合的.net和React应用程序,但不适用于我的新React应用程序。

我的目录结构是wwwroot> Dashboard。 我将生产版本复制到此仪表板文件夹。

我的webconfig是:

`<?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
          <system.webServer>
            <handlers>
                <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
            </handlers>
            <aspNetCore processPath="dotnet" arguments=".\Dashboard.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
            <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" />
                                    <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
                                </conditions>
                            <action type="Rewrite" url="/" />
                        </rule>
                    </rules>
                </rewrite>
            </system.webServer>
        </location>
    </configuration>`

在此输入图像描述

据我所知,asp.net核心应用程序使用services.AddSpaStaticFiles来提供React应用程序而不是使用url重写。

我建议您检查Startup.cs的Configure和ConfigureServices方法,以确保添加了SPA设置。

代码如下:

     public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

        // In production, the React files will be served from this directory
        services.AddSpaStaticFiles(configuration =>
        {
            configuration.RootPath = "ClientApp/build";
        });
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseSpaStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller}/{action=Index}/{id?}");
        });

        app.UseSpa(spa =>
        {
            //the source path of the react application
            spa.Options.SourcePath = "ClientApp";

            if (env.IsDevelopment())
            {
                spa.UseReactDevelopmentServer(npmScript: "start");
            }
        });
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM