Linux CentOS 使用service运行.NET Core项目

先新建一个web项目发布到/var/www/service.web

Linux CentOS 使用service运行.NET Core项目_第1张图片

再新建nginx文件/etc/nginx/conf.d/oms.cangzhouxiaozao.conf

内容为:

server {
    charset utf-8;
    client_max_body_size 128M;
    listen 80;
    server_name oms.cangzhouxiaozao.com;
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_min_length 1100;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/css application/json text/javascript application/javascript;
    access_log off;

    root /var/www/service.web;
    

    location ~ \.well-known/acme-challenge/* {
    }	
    
    location / {
        index index.html;
        # Redirect everything that isn't a real file to index.php
        #try_files $uri $uri/ /index.php$is_args$args;
        proxy_pass http://localhost:5010/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_cache_bypass $http_upgrade;
        #proxy_redirect  off;
        proxy_set_header    Host         $host;
        proxy_set_header    X-Real-IP           $remote_addr;
        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto $scheme;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout              90;
        proxy_read_timeout              90;
        proxy_buffers                   32 4k;
    }

    #listen  443 ssl http2;
    #ssl on;

    #ssl_certificate /etc/nginx/ssl/oms.bjcarlink.com/fullchain.cer; #(证书公钥)  
    #ssl_certificate_key /etc/nginx/ssl/oms.bjcarlink.com/oms.bjcarlink.com.key; #(证书私钥)  
     
    #ssl_session_timeout  5m;
    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;     #指定SSL服务器端支持的协议版本
    #ssl_ciphers  HIGH:!aNULL:!MD5;
    ##ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;    #指定加密算法
    #ssl_prefer_server_ciphers   on;    #在使用SSLv3和TLS协议时指定服务器的加密算法要优先于客户端的加密算法
}

执行

nginx -s reload

新建一个/etc/systemd/system/xxxx.service服务文件

内容为:

[Unit]
Description=Oms.Cangzhou Application running on CentOS
[Service]
ExecStart=/usr/bin/dotnet /var/www/service.web/service.web.dll --basePath /var/www/service.web/ --contentRoot /var/www/service.web/
Restart=always
RestartSec=5
SyslogIdentifier=oms.cangzhouxiaozao
User=root
Environment=ASPNETCORE_ENVIRONMENT=Development 
[Install]
WantedBy=multi-user.target


 

然后运行xxxx.service文件

这时该服务就创建完成了,就可以通过服务的方式启动/停止.NET Core项目了。

启动服务

systemctl start xxxx

查看服务运行状态 

systemctl status xxxx

停止服务 

systemctl stop xxxx

 

 

你可能感兴趣的:(Linux,ASP.NET,Core)