繁体   English   中英

在 Ubuntu 和 Plesk 中使用 ASP.NET Core 时出错

[英]Error using ASP.NET Core in Ubuntu with Plesk

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

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

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

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

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

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

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

在此处输入图片说明

有人可以提示我寻找解决此错误的地方吗?

有什么我可以检查以接收有关错误的更多详细信息吗?

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

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

从 Plesk Location 可以临时禁用 nginx服务器管理 -> 工具和设置 -> 服务 -> 反向代理服务器 (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 状态,并且您将使用 nginx 启动并运行 Plesk - 因为使用 systemctl 为 apache 和活动和正在运行的 dotnet 核心提供服务的反向代理。

暂无
暂无

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

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