linux 部署 Asp.net core

一、net7.0环境搭建

net 7.0搭建

二、安装配置nginx

1、安装nginx

sudo yum install yum-utils
sudo dnf install nginx

2、启动nginx(需要先确保80端口未被其他程序占用)

systemctl start nginx

3、设为开机启动

systemctl enable nginx

4、查看版本

nginx -v

5、配置nginx文件,覆盖nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    client_max_body_size 500m;

    server {
        listen        80;
        server_name  _;
        location / {
            proxy_pass         http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_connect_timeout       600;
            proxy_send_timeout          600;
            proxy_read_timeout          600;
            send_timeout                600;
        }
    }
}

6、验证配置

sudo nginx -t

7、重载

sudo nginx -s reload

三、创建服务

以sscms系统为例

创建服务定义文件 sscms.servic

sudo touch /etc/systemd/system/sscms.service

将以下内容保存至 /etc/systemd/system/sscms.service:

[Unit]
Description=SSCMS

[Service]
WorkingDirectory=/var/www
ExecStart=/usr/bin/dotnet /var/www/SSCMS.Web.dll
Restart=always


#Restart service after 10 seconds if the sscms service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=sscms
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

保存文件并启用服务。

sudo systemctl enable sscms.service

运行服务,并确认它正在运行。

sudo systemctl start sscms.service
sudo systemctl status sscms.service

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值