首页 文章

尝试启动Kestrel时使用UseUrls()时权限被拒绝错误

提问于
浏览
0

我正在尝试在我的mac上运行asp.net core 2.1应用程序,并且在我指定UseUrls()选项时收到错误“Permission Denied”并且Kestrel无法启动 .

这是我的program.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上启动

1 回答

  • 1

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

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

    如果您想使用主机名进行访问,则需要修改 /etc/hosts 文件以将主机名映射到localhost,但是您需要指定端口 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;
      }
    }
    

相关问题