首页 > 系统相关 >Centos7 部署NetCore6.0 Web Api

Centos7 部署NetCore6.0 Web Api

时间:2023-01-18 15:11:21浏览次数:56  
标签:http xxx server Centos7 nginx xx Api dotnet NetCore6.0

一、安装dotnet环境

第一步

sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

第二步

sudo yum install dotnet-sdk-6.0
第一次:Is this ok [y/d/N] y(确认下载安装包)

第二次:Is this ok [y/d/N] y(下载完成,确认安装)

 

第三步

sudo yum install dotnet-runtime-6.0

安装完成

通过dotnet --info命令查看是否安装完成,下面截图的是安装成功的显示

 

二、打包发布NetCore WEB API程序

1.vs中右键项目选择"发布"

2.如下图

 

 

 

 

 

在服务器创建文件夹,如dotnet_api,使用ftp将打包的文件发布到服务器创建的文件夹里

 

三、跑起来发布的WEB API

dotnet xxxx.dll --urls http://*:5000
然后再浏览器输入服务器IP:5000就可以访问发布的WEB API了

这样虽然跑起来了,但是Shell一关闭就不行了,这肯定不行,所以我们得给发布的WEB API做成自启动。

 

四、自启动,类似windows服务

1.创建自启动文件(再 /etc/systemd/system/目录里)

vim /etc/systemd/system/xxx.service

 配置文件的内容

复制代码
[Unit]
Description=xx.service

[Service]
WorkingDirectory=/site/xx/xx/www
ExecStart=/usr/share/dotnet/dotnet /site/xx/xx.dll --urls http://*:5000
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=AspnetCore
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=muti-user.target

复制代码

2.设置为自启动

systemctl enable xxx.service

3.启动服务

systemctl start xxx.service

4.查看服务状态

systemctl status xxx.service

这个时候就可以访问WEB API了

 

五、使用nginx做代理转发域名到5000端口

1.安装nginx

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum install -y nginx

2.启动nginx

sudo systemctl start nginx.service

3.配置nginx域名转发(打开/etc/nginx/文件夹下找到nginx.conf文件打开进行编辑)

复制代码

#user nginx;
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
     worker_connections 1024;
}

http {
    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;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 4096;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
       listen 80;
       listen [::]:80;
       server_name _;
       root /usr/share/nginx/html;

       # Load configuration files for the default server block.
       include /etc/nginx/default.d/*.conf;

       error_page 404 /404.html;
       location = /404.html {
        }

       error_page 500 502 503 504 /50x.html;
       location = /50x.html {
       }
    }
    server {
       listen 80;
       server_name api.www.xx.com;
       location / {
          proxy_pass http://localhost:5000;
       }
    } 
    server{
       listen 80;
       server_name page.www.xx.com;
       location / {
             alias /站点路径/xx/page/www/;
             index index.html index.htm;
           }
     }
}

 

复制代码

 配置好了重启一下服务就可以了:

 sudo systemctl restart nginx.service

就可以通过域名访问发布的WEB API了

六、Nginx怎么配置SSL

复制代码
server {
         listen      443 default ssl;这里要加上default ssl否则访问会报错(ERR_SSL_PROTOCOL_ERROR)
         server_name xx.xxx.com;
         ssl_certificate /路径/xxx_bundle.crt;
         ssl_certificate_key /路径/xxx.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
         location / {
            proxy_pass http://localhost:5000;
         }
     }
 server {
         listen       80;
         server_name xxx.xxx.com;
         rewrite ^/(.*)$ https://xxx.xxx.com:443/$1 permanent;
     }
同样的配置好了需要重启nginx服务
复制代码

 

转载来源: https://www.cnblogs.com/cheng8/p/16079449.html

标签:http,xxx,server,Centos7,nginx,xx,Api,dotnet,NetCore6.0
From: https://www.cnblogs.com/wlzx-dic/p/17059856.html

相关文章

  • Python使用pyppeteer搭建网页截图api
    因为跨语言需要,打算把pyppeteer、图片压缩、awsS3封装成一个api来调用。首先自然是要安装依赖pip3installpillowboto3pyppeteer运行一次脚本,pyppeteer会自动下载最......
  • centos7系统日志
    系统日志的保存目录一般在cd/var/log主要的几个日志如下1、/var/log/boot.log(自检过程)2、/var/log/cron(crontab守护进程crond所派生的子进程的动作)3、/var/log/maillog......
  • day14-常用API
    1.API1.1API概述【理解】什么是API​ API(ApplicationProgrammingInterface):应用程序编程接口java中的API​ 指的就是JDK中提供的各种功能的Java类,这些类......
  • day15-常用API
    1.时间日期类1.1Date类(应用)计算机中时间原点1970年1月1日00:00:00时间换算单位1秒=1000毫秒Date类概述Date代表了一个特定的时间,精确到毫秒Date类构......
  • Centos7上部署Jenkins部署
    Centos7上部署Jenkins部署一、Jenkins是用Java开发的,安装Jenkins之前首先需要安装JDK。yuminstalljava-1.8.0-openjdk*-y#也可以参考源码安装jdkhttps://www.......
  • CentOS7更新阿里云yum源
    CentOS7更新阿里云yum源,​​参考阿里云官方文档​​,操作如下:1,备份旧源文件mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup2,下载新源文件w......
  • CentOS7首次安装VirtualBox增强功能失败解决
    从VMwareworkstation转换到VirtualBox,总会少许有点阵痛期,不花钱的软件咱们还得体谅体谅。首次在VirtualBox上安装增强功能就失败了,错误信息(如图):Kernelheadersnotfoundf......
  • cat <<-EOF > /etc/yum.repo.d/centos72.repo 没有那个文件或目录
    cat不仅可以显示文件内容,还可以创建文件,但是遇到执行脚本时提示“没有那个文件或目录” 文件名:create_yum.sh1#!/bin/sh23repo_PATH=/etc/yum.repo.d/45cat......
  • 关于如何在CentOS7中如何利用Docker中的Nginx容器反向代理MantisBT容器并连接宿主机数
    是的标题确实很长,意思就是,我现在Docker里面有MantisBT和Nginx,系统里安装了MySQL,要如何把他们连在一起?注意因为MantisBT与MySQL高版本会有字符集不兼容的问题,所以我采用了......
  • xlwings rest api
    https://pbihub.cn/blog/964/created_athttps://docs.xlwings.org/zh_CN/latest/rest_api.htmlxlwings>=0.13.0flask>=1.01.运行CMD xlwingsrestapirun-host0.......