简体   繁体   English

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

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

I installed NET Core SDK on Ubuntu 18.04 following the official guide:我按照官方指南在 Ubuntu 18.04 上安装了 NET Core SDK:

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

I created a C# Hello World project with command dotnet new razor and published with dotnet publish .我使用命令dotnet new razor创建了一个C# Hello World项目,并使用dotnet publish

I configured a new domain in Plesk with a sub-domain.我在 Plesk 中配置了一个带有子域的新域。

I configured (using the official reference: https://docs.microsoft.com/it-it/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-2.2 ) in Plesk, under Apache & nginx Settings , with the following example:我在 Plesk 中的Apache & nginx Settings下配置(使用官方参考: https : //docs.microsoft.com/it-it/aspnet/core/host-and-deploy/linux-apache? view = aspnetcore Apache & nginx Settings ,以下面的例子:

Additional directives for HTTP/HTTPS: 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 

I moved the published project under subdomain folder and started it with command dotnet myproject.dll我将已发布的项目移动到子域文件夹下并使用命令dotnet myproject.dll启动它

I received the following output:我收到以下输出:

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.

Opening sub.mydomain.com in browser I receive the following error:在浏览器中打开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

In subdomain log I can see only this:在子域日志中,我只能看到:

在此处输入图片说明

Can someone give me a hint to look somewhere to resolve this error?有人可以提示我寻找解决此错误的地方吗?

There's something I can check to receive further details about the error?有什么我可以检查以接收有关错误的更多详细信息吗?

Fist you need temporary to disable the nginx since using plesk as platform panel, flow of data exchange is:由于使用plesk作为平台面板,因此您需要暂时禁用nginx ,数据交换流程为:

  • end-user-request-start -> nginx -> apache [ script/code executed ] -> reverse/proxy request back to nginx -> final result to end-user.最终用户请求开始 -> nginx -> apache [脚本/代码执行] -> 反向/代理请求返回 nginx -> 最终结果给最终用户。

Plesk Location from were you can temporary disable the nginx : Server Managment -> Tools&Settings -> Services -> Reverse Proxy Server (nginx ) - ( click on stop icon and wait for a while, once the service is stopped green check mark will disappear and grey circle will be present )从 Plesk Location 可以临时禁用 nginx服务器管理 -> 工具和设置 -> 服务 -> 反向代理服务器 (nginx) -(单击停止图标并等待一段时间,一旦服务停止绿色复选标记将消失并且将出现灰色圆圈)

Now all request will be served by only apache2 , and then following official Microsoft Apache2 directives can be applied and sub-domain will be able to serve the requests that are ending into Kestrel server ( which will have proxy and reverse proxy directives to be able to communicate with apache 2 )现在所有请求将仅由 apache2 提供服务,然后可以应用以下官方 Microsoft Apache2 指令,并且子域将能够为以 Kestrel 服务器结尾的请求提供服务(它将具有代理和反向代理指令,以便能够与 apache 通信 2 )

Also very important !也很重要! the same apache directives that you apply under sub-domain, it's mandatory and accordingly to be applied also under apache directives main domain.与您在子域下应用的相同 apache 指令,它是强制性的,因此也应在 apache 指令主域下应用。 Once you are done with it, and testing is completed then , you can re-enable the nginx reverse proxy service , and under appropriate domain, sub-domain, under nginx settings , check-box Proxy mode - needs to be selected, in order the nginx to use the apache and within the directives完成后,测试完成后,您可以重新启用nginx反向代理服务,并在适当的域下,子域下,在nginx设置下,复选框代理模式 - 需要选中,以便nginx 使用 apache 并在指令中

example for apache directives if sub-domain has ternary or quarter name : main domain: main-domain.com如果子域具有三元或四分之一名称,则 apache 指令的示例:主域: main-domain.com

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

sub-domain: subdomain-2.sub-domain-name1.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

Also please include in both, sud-main and main-domain, apache2 directives on top as first line:还请在 sud-main 和 main-domain 中包含 apache2 指令作为第一行:

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

And you can change if you like the errors and access activities in the logs to appear in the same log as apache2 is using ( error.log and access.log ) - this minor change will enable using plesk webplatform and mobile app to appear the logs and activities to be accessible within.如果您希望日志中的错误和访问活动显示在与 apache2 使用的相同的日志中( error.log 和 access.log ),您可以进行更改 - 这一微小更改将允许使用 plesk webplatform 和移动应用程序显示日志以及可在其中访问的活动。

That changes can be done with small change in the following lines:可以通过以下几行中的小更改来完成更改:

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

Also if you deside to use the dotnet core application as an service as it's described into Microsoft link: using systemctl , be carrefull that installation of systemctl will substitute the upstream ( service module/controler which plesk is using , at least in my Ubuntu 14.04 messed-up, potentially the kernel version and systemctl since is older, and plesk is not re-writing in the same place the symbolic links, )此外,如果您希望将 dotnet 核心应用程序用作 Microsoft 链接中描述的服务:使用 systemctl ,请注意 systemctl 的安装将替代上游(plesk 正在使用的服务模块/控制器,至少在我的 Ubuntu 14.04 中被搞砸了) -up,可能是内核版本和 systemctl 因为较旧,并且 plesk 不会在符号链接的同一位置重写,)

- Only if your server is Ubuntu 14.04 and Plesk and you have installed the systemctl ( which was not installed by default ) execute the following to recover the symbolic link issues, ( in this use-case scenario, systemctl monitors/runs the dotnet core 2.1 application ) - 仅当您的服务器是 Ubuntu 14.04 和 Plesk 并且您已安装 systemctl(默认情况下未安装)执行以下操作以恢复符号链接问题,(在此用例场景中,systemctl 监视/运行 dotnet core 2.1应用 )

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

And after this command is executed, into Plesk WebPro WebPanel, under-Home, within notification error message there are ( two links marked with here ) click - here the link that refers to: recreate all-apache2 configuration files, wait for it, and once done the Plesk Server will continue with OK state, and you'll have Plesk up and running with both nginx - as reverse-proxy towards apache and active and running dotnet core are service using systemctl.执行此命令后,进入 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