千家信息网

怎么在nginx中部署.net core站点

发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,今天就跟大家聊聊有关怎么在nginx中部署.net core站点,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。步骤aspnetcore程序端口
千家信息网最后更新 2025年02月03日怎么在nginx中部署.net core站点

今天就跟大家聊聊有关怎么在nginx中部署.net core站点,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

步骤

aspnetcore程序端口号5001,实际外部端口号8001,相当于把8001收到的请求转发给5001.

把发布出来的文件全部丢掉 /var/www/JuXiangTou 里面去。可以用scp命令或者winscp客户端

  1. centos 7.x

  2. aspnet core 的运行环境,不需要装sdk,一般sdk里面是包含runtime的

 yum install libunwind libicuyum install aspnetcore-runtime-2.1

nginx,一个反向代理服务,把过来的http请求转发给实际的aspnetcore处理

sudo yum install epel-releasesudo yum install nginxsudo systemctl start nginxsudo systemctl enable nginx

装好nginx要配置端口之类的。

 cd /etc/nginx/

nginx.conf是默认的配置文件,基本不用动。

 cd conf.dvim kestrel-juxiangtou.conf

下面主要就是两个端口号的需要改一下,其他都可以不用改动。

server {    listen 8001;    location / {        proxy_pass http://localhost:5001;        proxy_http_version 1.1;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Connection keep-alive;        proxy_set_header Host $http_host;        proxy_cache_bypass $http_upgrade;    }}

保存退出

验证一下配置,然后重新载入

sudo nginx -t sudo nginx -s reload

防火墙firewall-cmd。不一定装过,要看环境。

systemctl status firewalldfirewall-cmd --zone=public --add-port=8001/tcp --permanentfirewall-cmd --reloadsystemctl restart firewalld.service

建一个服务,用于维护dotnetcore的程序进程

cd /etc/systemd/systemvim kestrel-juxiangtou.service
[Unit]Description=JuXiangTou[Service]WorkingDirectory=/var/www/JuXiangTouExecStart=/usr/bin/dotnet /var/www/JuXiangTou/Site.WebApi.dllRestart=alwaysRestartSec=10SyslogIdentifier=JuXiangTouUser=rootEnvironment=ASPNETCORE_ENVIRONMENT=Production[Install]WantedBy=multi-user.target

保存退出

systemctl restart kestrel-juxiangtou.service

看完上述内容,你们对怎么在nginx中部署.net core站点有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。

0