0

您好我正在尝试使用 apache 服务器和反向代理在 linux 机器上部署一个 asp.net core 2.2 应用程序,但我在查看我的网络应用程序时遇到问题。我看到这个:

在此处输入图像描述

我将向您展示我所做的所有配置

按照这个微软教程:https ://docs.microsoft.com/es-es/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-2.2

我首先配置了我的 Startup.cs 代码,如下所示:

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        //app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseForwardedHeaders(new ForwardedHeadersOptions
        {
            ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
        });

        app.UseAuthentication();

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

像这样的launchSetting.json:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:63992",
      "sslPort": 44365
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "ElectransCloudServices": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:5000"
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}"
    }
  }
}

然后我编译了我的项目并进入我的 linux 机器,执行命令 dotnet publish --configuration Release -o /var/www/ElectransClo​​udServices 将我的项目部署到 apache 配置的正确目录中。

这部分是项目配置。现在我将向您展示我的服务器配置:

我使用以下脚本在 /etc/apache2/sites-enabled/ 中创建了一个名为 electrotransapp.conf 的配置文件:

<VirtualHost *:*>
    RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
</VirtualHost>

<VirtualHost *:8080>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
    DocumentRoot /var/www/ElectransCloudServices
    ServerName localhost
    # ServerAlias *.example.com
    ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
    CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
</VirtualHost>

我正在使用 8080 端口。

然后我使用以下参数修改了文件 /etc/apache2/apache2.conf:

<Directory /var/www/ElectransCloudServices>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

ServerName localhost

最后我运行命令 systemctl restart apache2

做完这一切之后,我看到了我给你看的第一张图片。我很确定错误出在 apache 配置中,但我不知道我做错了什么。有什么帮助吗?

先感谢您

4

0 回答 0