【问题标题】:Permission denied error when using UseUrls() when trying to launch Kestrel尝试启动 Kestrel 时使用 UseUrls() 时出现权限被拒绝错误
【发布时间】:2018-11-19 16:22:40
【问题描述】:

我正在尝试在我的 Mac 上运行 asp.net core 2.1 应用程序并收到错误“权限被拒绝”并且当我指定 UseUrls() 选项时 Kestrel 无法启动。

这是我的程序.cs

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseKestrel()
            .UseUrls("http://api.dev.mysite.com")
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();
}

如果我注释掉“UseUrls”,则该网站在https://localhost:5001 上启动正常

【问题讨论】:

    标签: macos kestrel asp.net-core-2.1


    【解决方案1】:

    Kestrel 不绑定到特定的主机名。 UseUrls() 允许您仅绑定到网络接口,例如:

    http://localhost:5000
    http://127.0.0.1:5001
    http://*:5002
    

    如果您想使用主机名进行访问,您需要修改 /etc/hosts 文件以将主机名映射到本地主机,但您需要指定端口http://api.dev.mysite.com:5001除非它设置为监听 80 或 443(对于 https)。或者使用反向代理,如 IIS/Nginx/Apache。对于 Nginx 的配置是:

    server {
      listen       80;
      server_name  api.dev.mysite.com;
      location / {
        proxy_pass http://127.0.0.1:5001;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-09
      • 1970-01-01
      • 1970-01-01
      • 2019-01-30
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2012-01-01
      相关资源
      最近更新 更多