gpt4 book ai didi

linux - 服务文件未在 Ubuntu 上运行,但项目/文件在 Putty/终端上运行良好(ASP.NET Core 网站)

转载 作者:行者123 更新时间:2023-12-04 18:48:34 26 4
gpt4 key购买 nike

当我在 Ubuntu 20.04 中从 Putty 运行 ASP.NET Core 网站时:

/usr/bin/dotnet /root/dev/myWebApp/myWebApp/myWebApp.dll
或者
dotnet /root/dev/myWebApp/myWebApp/myWebApp.dll
它可以在浏览器上正常运行网站: localhost:5000https://localhost:5001但是当我尝试使用以下命令将其作为服务“website.service”启动时:
sudo nano /etc/systemd/system/website.service
并写入文件:
[Unit]
Description=Example .NET Web API App running on Ubuntu

[Service]
WorkingDirectory=/root/dev/myWebApp/myWebApp
ExecStart=/usr/bin/dotnet /root/dev/myWebApp/myWebApp/myWebApp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target
接着:
sudo systemctl enable website.service
sudo systemctl daemon-reload
sudo systemctl start website.service
服务启动但 localhost:5000https://localhost:5001不打开
sudo systemctl status website.service
给出:
website.service - Example .NET Web API App running on Ubuntu
Loaded: loaded (/etc/systemd/system/website.service; enabled; vendor prese>
Active: activating (auto-restart) (Result: exit-code) since Sat 2021-08-21>
Process: 2421 ExecStart=/usr/bin/dotnet /root/dev/myWebApp/myWebApp/myWebAp>
Main PID: 2421 (code=exited, status=200/CHDIR)
笔记:
重新创建 ASP.NET 核心环境和项目的步骤:
安装 dotnet core 5.0
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update
sudo apt install apt-transport-https
sudo apt update
sudo apt install dotnet-sdk-5.0
创建、构建和发布 asp.net 核心项目
mkdir dev
cd dev
dotnet --info
dotnet new webApp -o myWebApp //Create a basic web application that should listen on 5000 port
cd myWebApp
dotnet build //Builds the project
dotnet publish -c release -o myWebApp //Publishes the project as a myWebApp.dll on /root/dev/myWebApp/myWebApp/myWebApp.dll path, it should run in "website.service" file
我遵循了本教程: https://www.youtube.com/watch?v=M3G4bNRZTDo部分来自时间:5:44: https://www.youtube.com/watch?v=Sw6USmvt60s

最佳答案

我找到了答案,服务文件不从/root/dev 文件夹运行 dll,它从/var/www 文件夹运行文件正常。

关于linux - 服务文件未在 Ubuntu 上运行,但项目/文件在 Putty/终端上运行良好(ASP.NET Core 网站),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68870919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com