• .NET Core 3.1+Vue的前后端分离部署方案


    使用nginx进行部署,下载地址:https://nginx.org/en/download.html

    .NET Core 3.1,下载地址:https://dotnet.microsoft.com/download/dotnet-core

    部署环境安排,可以是linux中的centos或者Ubuntu,我准备了win2012 r2(建议用win2016,2012需要打补丁支持.NET Core),方便不懂运维的同事可以操作(哈哈)

    .NET Core 案例项目如下:本地运行后访问http://localhost:4000/api/user/auth/login 测试用get,发布走post

        [Area("user")]
        [Route("api/[area]/[controller]")]
        [ApiController]
        public class AuthController : ControllerBase
        {
            private IUserService _userService;
    
            public AuthController(IUserService userService)
            {
                _userService = userService;
            }
    
            [HttpPost("login")]
            //[HttpGet("login")]
            public IActionResult Login(string username, string password)
            {
                var tokenHandler = new JwtSecurityTokenHandler();
                var key = Encoding.ASCII.GetBytes("aaaaaabbbbbbcccc");
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject = new ClaimsIdentity(new[] { new Claim("id", "1") }),
                    Expires = DateTime.UtcNow.AddDays(7),
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
                };
                var token = tokenHandler.CreateToken(tokenDescriptor);
                string tokenStr = tokenHandler.WriteToken(token);
                return Ok(new  {
                    access_token= tokenStr,
                    token_type ="bearer",
                    expires_in=7*60
                });
                //return Ok(token);
            }
        }

    Vue案例项目:Vuetify做UI组件,其他是全家桶

     

     使用nginx进行部署:内部对/api下的请求做代理,让他去访问WebApi,80给Vue部署前台,这是最简单配置,如果你对头信息有要求可以在把头信息加上

     两个都跑起来,这边WebApi自宿主,就不在安装IIS了,前台的请求到了内部就转发了,

     

  • 相关阅读:
    资源网站
    远程服务SSH
    Samba服务配置
    练习raid5
    raid(0、1)
    NFS服务器配置(windows访问)
    LVM磁盘阵列
    ISCSI服务器配置
    Zibbix监控
    MySQL Replication配置
  • 原文地址:https://www.cnblogs.com/RainbowInTheSky/p/13901929.html
Copyright © 2020-2023  润新知