首页 > 解决方案 > 在带有 Plesk 的 Ubuntu 中使用 ASP.NET Core 时出错

问题描述

我按照官方指南在 Ubuntu 18.04 上安装了 NET Core SDK:

https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install

C# Hello World使用命令创建了一个项目dotnet new razor并使用dotnet publish.

我在 Plesk 中配置了一个带有子域的新域。

我在 Plesk 中配置(使用官方参考:httpsApache & nginx Settings ://docs.microsoft.com/it-it/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-2.2 ),在 下,具有以下例子:

HTTP/HTTPS 的附加指令:

ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName sub.mydomain.com
ServerAlias *.mydomain.com
ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
CustomLog ${APACHE_LOG_DIR}helloapp-access.log common 

我将发布的项目移动到子域文件夹下并使用命令启动它dotnet myproject.dll

我收到以下输出:

Hosting environment: Production
Content root path: /var/www/vhosts/mydomain.com/sub.mydomain.com
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

在浏览器中打开sub.mydomain.com我收到以下错误:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at logx.edotto.com Port 80

在子域日志中,我只能看到:

在此处输入图像描述

有人可以给我一个提示,让我去某个地方解决这个错误吗?

我可以检查一下以接收有关该错误的更多详细信息?

标签: c#ubuntu-18.04plesk

解决方案


由于使用 plesk 作为平台面板,您需要暂时禁用 nginx,数据交换流程为:

  • 最终用户请求开始-> nginx-> apache [脚本/代码执行]-> 反向/代理请求返回到 nginx-> 最终结果给最终用户。

您可以临时禁用 nginx 的 Plesk 位置服务器管理 -> 工具和设置 -> 服务 -> 反向代理服务器(nginx) - (单击停止图标并等待一段时间,一旦服务停止,绿色复选标记将消失并将出现灰色圆圈)

现在所有请求将仅由 apache2 提供服务,然后可以应用以下官方 Microsoft Apache2 指令,并且子域将能够服务于以 Kestrel 服务器结尾的请求(它将具有代理和反向代理指令能够与 apache 通信 2)

也很重要!您在子域下应用的相同 apache 指令,它是强制性的,因此也适用于 apache 指令主域。一旦你完成它,并且测试完成,你可以重新启用 nginx 反向代理服务,并在适当的域下,子域下,在 nginx 设置下,复选框代理模式 - 需要选中,顺序nginx 使用 apache 并在指令中

如果子域具有三元或季度名称,则 apache 指令的示例: 主域: main-domain.com

**- ServerName: subdomain-name2.sub-domain-name1.main-domain.com
**- ServerAlias: *.main-domain.com

子域: subdomain-2.sub-domain-name1.main-domain.com

**- ServerName: subdomain-name2.sub-domain-name1.main-domain.com
**- ServerAlias: *.subdomain-1.main-domain.com

还请在 sud-main 和 main-domain 中都包含 apache2 指令作为第一行:

RequestHeader 设置“X-Forwarded-Proto”expr=%{REQUEST_SCHEME}

如果您希望日志中的错误和访问活动出现在与 apache2 使用的日志相同的日志中(error.log 和 access.log),您可以进行更改 - 这个微小的更改将允许使用 plesk webplatform 和移动应用程序来显示日志以及可在其中访问的活动。

可以通过以下几行中的微小更改来完成更改:

ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log 组合

此外,如果您打算将 dotnet 核心应用程序用作 Microsoft 链接中描述的服务:使用 systemctl ,请注意 systemctl 的安装将替代上游(plesk 正在使用的服务模块/控制器,至少在我的 Ubuntu 14.04 混乱中) -up,可能是内核版本和 systemctl 因为较旧,并且 plesk 不会在同一个地方重写符号链接,)

- 仅当您的服务器是 Ubuntu 14.04 和 Plesk 并且您已安装 systemctl(默认情况下未安装)执行以下操作以恢复符号链接问题,(在此用例场景中,systemctl 监控/运行 dotnet core 2.1应用 )

sed -i.orig s/systemctl/systemctl_pp/g /opt/psa/admin/sbin/pleskrc

并且执行完这条命令后,进入Plesk WebPro WebPanel,在Home下,在通知错误信息里面有(两个链接标有这里)点击-这里链接指的是:recreate all-apache2 configuration files,等待它,然后完成后,Plesk 服务器将继续以 OK 状态运行,您将启动 Plesk 并使用两个 nginx 运行 - 作为对 apache 的反向代理,并且活动和运行的 dotnet 核心是使用 systemctl 的服务。


推荐阅读