gpt4 book ai didi

linux - .Net Core 3.1 在 Centos 7 上部署

转载 作者:行者123 更新时间:2023-12-04 19:35:27 26 4
gpt4 key购买 nike

我正在尝试在 Centos 7 + Plesk 服务器上运行我的 .net Core Web api 应用程序。我的应用程序将在子域中运行。我从 Plesk 面板设置了一个子域并传输了我的文件。之后,我一步一步地按照下面的文章,这不是一篇解释性或帮助性很强的文章。
https://docs.microsoft.com/tr-tr/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-3.1
首先这个路径不存在/etc/nginx/sites-available/default。于是在其他文章的帮助下,我在etc/nginx/conf.d文件夹下创建了文件api.mysite.com.conf。

To configure Nginx as a reverse proxy to forward HTTP requests to yourASP.NET Core app, modify /etc/nginx/sites-available/default. Open itin a text editor, and replace the contents with the following snippet.

    server {
listen 80;
server_name api.mysite.com *.mysite.com;
location / {
.... same as in docs.
}
}
其次,我按照文档创建了服务文件。 “/usr/bin/dotnet”这个目录在这一步是不存在的,文件再次不足为奇。
我通过键入“/usr/share/dotnet/dotnet”而不是“/usr/bin/dotnet”解决了这一步。

sudo nano /etc/systemd/system/kestrel-webapi.service

[Unit]
Description=Example .NET Web API App running on Centos 7

[Service]
WorkingDirectory=/var/www/vhosts/mysite.com/api.mysite.com
ExecStart=/usr/share/dotnet/dotnet /var/www/vhosts/mysite.com/api.mysite.com
创建服务后,我运行它没有任何问题。
下一步是 Apache 配置。
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-3.1

Configuration files for Apache are located within the/etc/httpd/conf.d/ directory. Any file with the .conf extension isprocessed in alphabetical order in addition to the moduleconfiguration files in /etc/httpd/conf.modules.d/, which contains anyconfiguration files necessary to load modules.


我正在“/etc/httpd/conf.d”文件中创建一个配置文件。
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr=${REQUEST_SCHEME}
</VirtualHost>

<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName www.mysite.com
ServerAlias *.mysite.com
ErrorLog ${APACHE_LOG_DIR}webapi-error.log
CustomLog ${APACHE_LOG_DIR}webapi-access.log common
</VirtualHost>
进行此配置后,按顺序运行以下命令时出现错误。

sudo service httpd configtest


sudo systemctl restart httpd

[Fri May 28 19:35:02.344213 2021] [core:warn] [pid 25339:tid 139880432744576] AH00111: Config variable ${REQUEST_SCHEME} is not defined
[Fri May 28 19:35:02.344814 2021] [core:warn] [pid 25339:tid 139880432744576] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Fri May 28 19:35:02.344853 2021] [core:warn] [pid 25339:tid 139880432744576] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
Syntax OK


May 28 19:39:16 localhost.localdomain httpd[25740]: [Fri May 28 19:39:16.897163 2021] [core:warn] [pid 25740:tid 140630647605376] AH00111: Config variable ${REQUEST_SCHEME} is not defined
May 28 19:39:16 localhost.localdomain httpd[25740]: [Fri May 28 19:39:16.897775 2021] [core:warn] [pid 25740:tid 140630647605376] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
May 28 19:39:16 localhost.localdomain httpd[25740]: [Fri May 28 19:39:16.897825 2021] [core:warn] [pid 25740:tid 140630647605376] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
May 28 19:39:16 localhost.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
May 28 19:39:16 localhost.localdomain systemd[1]: Failed to start The Apache HTTP Server.
May 28 19:39:16 localhost.localdomain systemd[1]: Unit httpd.service entered failed state.
May 28 19:39:16 localhost.localdomain systemd[1]: httpd.service failed.
在做这些操作之前,当我通过浏览器打开 api.mysite.com 时,出现了 plesk panel 欢迎页面。我通过编写以下代码解决了这个问题,现在我得到了 403 禁止错误。
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf_backup
如何解决以上两个问题?当我连接到 api.mysite.com 时,如何重定向到我的 Web api 应用程序?
我已经为此苦苦挣扎了 3 天,我在互联网上找不到合适的文章,有没有人可以帮助我?

最佳答案

我解决了这个问题。
当我们在 plesk 面板中创建域时,apache 会创建自己的配置文件,所以我所要做的就是在 plesk 面板的相关域的 Hosting & DNS 设置下的 Apache & nginx 中更改 Additional apache directives 设置。
Plesk --> 网站和域名 --> <> --> 主机和 DNS --> Apache 和 nginx
HTTP 的附加指令

Header set Access-Control-Allow-Origin "http://yourdomain.com"
Header set Access-Control-Allow-Headers "Access-Control-Allow-Headers, Origin, Accept,
X-Requested-With, Content-Type, Access-Control-Request-Method, Access-ControlRequest-Headers, Authorization, Content-Disposition"
Header set Access-Control-Allow-Methods "*"
Header set Access-Control-Allow-Credentials "true"
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
HTTPS 的附加指令
Header set Access-Control-Allow-Origin "https://yourdomain.com"
Header set Access-Control-Allow-Headers "Access-Control-Allow-Headers, Origin, Accept,
X-Requested-With, Content-Type, Access-Control-Request-Method, Access-ControlRequest-Headers, Authorization, Content-Disposition"
Header set Access-Control-Allow-Methods "*"
Header set Access-Control-Allow-Credentials "true"
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
如果您有 cors 问题,您可以添加以标题集开头的行。
完成所有这些之后,如果您的服务文件中准备好,您的应用程序将运行。

关于linux - .Net Core 3.1 在 Centos 7 上部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67746545/

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