如何使用Revese代理在Linux Apache服务器中部署Asp.net Core 2.2

时间:2019-05-20 07:07:42

标签: linux apache asp.net-core-mvc asp.net-core-2.2

您好,我正在尝试使用apache服务器和反向代理在Linux机器中部署asp.net core 2.2应用程序,但是我在查看Web应用程序时遇到了问题。我看到了:

enter image description here

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

此Microsoft教程之后: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}"
    }
  }
}

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

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

我已经使用以下脚本在/ etc / apache2 / sites-enabled /中创建了一个名为lectransapp.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配置中,但是我不知道我在做什么错。 有帮助吗?

提前谢谢

0 个答案:

没有答案