【问题标题】:Error using ASP.NET Core in Ubuntu with Plesk在带有 Plesk 的 Ubuntu 中使用 ASP.NET Core 时出错
【发布时间】:2019-09-03 13:43:57
【问题描述】:

我按照官方指南在 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-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.04 plesk


    【解决方案1】:

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

    • end-user-request-start -> nginx -> apache [ script/code executed ] -> 反向/代理请求返回 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 和移动应用程序显示可在其中访问的日志和活动。

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

    错误日志 ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log 合并

    此外,如果您打算将 dotnet 核心应用程序用作 Microsoft 链接中描述的服务:使用 systemctl,请注意 systemctl 的安装将替代上游(plesk 正在使用的服务模块/控制器,至少在我的Ubuntu 14.04 搞砸了,可能是内核版本和 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 下,在通知错误消息内有(标有 here 的两个链接)单击 - 这里链接指的是:recreate all -apache2 配置文件,等待它,一旦完成,Plesk 服务器将继续以 OK 状态运行,您将启动 Plesk 并使用两个 nginx 运行 - 作为对 apache 的反向代理,并且活动和正在运行的 dotnet 核心是使用 systemctl 的服务.

    【讨论】:

    • 此解决方案是否也适用于 Ubuntu 18.04?
    • 应该,但先创建备份。
    猜你喜欢
    • 2021-05-29
    • 1970-01-01
    • 2018-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 2023-03-24
    相关资源
    最近更新 更多