zoukankan      html  css  js  c++  java
  • ASP.Net Core Web API使用Nginx部署

    本文作为ASP.Net Core Web API学习的一部分,介绍了如何使用Nginx进行简单的负载配置。

    1、将ASP.Net Core Web API项目发布到不同的服务器

    例如,将项目发布到本地不同的文件夹中。

    2、使用dotnet命令启动已发布的ASP.Net Core Web API服务

    -> dotnet WebApi.dll --urls="http://*:3001" --ip="127.0.0.1" --port=3001

    -> dotnet WebApi.dll --urls="http://*:3002" --ip="127.0.0.1" --port=3002

    -> dotnet WebApi.dll --urls="http://*:3003" --ip="127.0.0.1" --port=3003

    3、安装Nginx

    在http://nginx.org/en/download.html下载安装Nginx稳定版,这里安装的版本是1.18.0。

    4、设置Nginx

    Nginx配置文件路径为nginx-1.18.0\conf\nginx.conf。

    (1) 配置端口

    Nginx启动不了时,可能就是因为端口被占用了,因此可以手动设置Nginx的端口。

    端口位置为nginx.conf -> http -> server -> listen,默认为80端口,可以修改为需要设置的端口。

    (2) 配置基于转发服务器

    server_name  localhost;

    server_name指令可以设置基于域名的虚拟主机,根据请求头部的内容,一个ip的服务器可以配置多个域名,多个域名之间以空格分开。

    (3) 设置代理路径

    location / {

             #root   html;

             #index  index.html index.htm;

             proxy_pass http://webApi; #设置代理转发,转发到服务器列表

    }

    (4) 设置服务器列表

    upstream webApi {

             server localhost:3001;

             server localhost:3002;

             server localhost:3003;

    }

    5、测试Nginx服务器

    假如api接口路径为http://localhost:3001/api/weatherforecast,在浏览器中输入http://localhost:80/api/ weatherforecast,则依次会调用3001、3002、3003端口所在服务器接口,对所有接口轮询调用。

    Nginx默认使用轮询策略转发请求到服务器列表,也可以设置权重等策略。

  • 相关阅读:
    apache配置文件参数优化
    apache 虚拟主机详细配置:http.conf配置详解
    Apache安装问题:configure: error: APR not found . Please read the documentation
    lamp安装
    Linux运维常用命令总结
    mysql主从日志的定期清理
    python写的分析mysql binlog日志工具
    mysql5.6主从参数详解
    京东MySQL监控之Zabbix优化、自动化
    CentOS 6.5 生产环境编译安装LNMP
  • 原文地址:https://www.cnblogs.com/xhubobo/p/14397064.html
Copyright © 2011-2022 走看看