简体   繁体   English

无法访问 Owin 自托管 RestApi - 部署到 AWS EC2 - Windows 2012 R2

[英]Unable to Access Owin Self hosted RestApi - Deployed to AWS EC2 - Windows 2012 R2

Following is the sample self hosting Rest API code, I have created with OWIN.以下是我使用 OWIN 创建的示例自托管 Rest API 代码。 It is working in my local machine.它在我的本地机器上工作。

i have hosted it in aws-ec2, and started as administrator.我将它托管在 aws-ec2 中,并以管理员身份启动。

I am able to access the Rest API from inside the instance (using chrome/IE) giving localhost as URL.我能够从实例内部(使用 chrome/IE)访问 Rest API,将本地主机设为 URL。

即时访问

But getting a Bad request invalid hostname, when i replace the localhost with public DNS of Instance (running within Instance's browser).但是,当我将本地主机替换为实例的公共 DNS(在实例的浏览器中运行)时,收到错误的请求无效主机名。

实例 DNS 名称

when i tried to access the RestApi from outside the instance browser from my local machine (browser/postman), it is returning status 0.当我尝试从本地计算机(浏览器/邮递员)的实例浏览器外部访问 RestApi 时,它返回状态 0。

从外部访问

Copied the code below.复制下面的代码。

class Program {
    static void Main(string[] args) {
        const string BaseUri = "http://localhost:65435";
        Console.WriteLine("Starting web Server...");
        WebApp.Start<Startup>(BaseUri);
        ...
    }
}

public class Startup {
    public void Configuration(IAppBuilder app) {
        var webApiConfiguration = ConfigureWebApi();
        app.UseWebApi(webApiConfiguration);
    }

    private HttpConfiguration ConfigureWebApi() {
        var config = new HttpConfiguration();
        config.Routes.MapHttpRoute(
            "DefaultApi",
            "api/{controller}/{id}",
            new { id = RouteParameter.Optional });
        return config;
    }
}

public class CompaniesController : ApiController {
    public IEnumerable<Company> Get() {
        return new List<Company>(){
                       new Company() { Id = 1, Name = "Microsoft" },
                       new Company() { Id = 2, Name = "Amazon" }
                   };
    }
}

I have created a Windows Server 2012 R2 - AWS EC2 instance.我创建了一个 Windows Server 2012 R2 - AWS EC2 实例。

Configured the instance:配置实例:

  1. To allow all traffic in inbound and outbound.允许所有入站和出站流量。
  2. Opened all ports.打开所有端口。
  3. I have disabled Windows Firewall我已禁用 Windows 防火墙
  4. I have tried to ping the DNS name from my local machine cmd, and it was success.我尝试从我的本地机器 cmd ping DNS 名称,它成功了。
  5. Web API is using, port number - 65435 (Ephemeral Port) Web API 正在使用,端口号 - 65435(临时端口)
  6. Owin version - 5.2.3.0, .Net version - 4.5 (4.5.2 is installed on EC2 instance) Owin 版本 - 5.2.3.0,.Net 版本 - 4.5(4.5.2 安装在 EC2 实例上)
  7. Changed the "localhost" in the code to public-dns (Same issue persists) and ip-address (throws an Exception - "Exception has been thrown by the target of an invocation.")将代码中的“localhost”更改为 public-dns(同样的问题仍然存在)和 ip-address(抛出异常 - “调用目标已抛出异常。”)

入站规则

出站规则

Please help me to configure this.请帮我配置一下。

You're starting the WebApp on localhost: 您正在localhost上启动WebApp

http://localhost:65435

It's started on the loopback adapter and not on the actual ethernet adapter that you're trying to access from outside. 它是在环回适配器上启动的,而不是在您尝试从外部访问的实际以太网适配器上启动的。 You need to start it with the server's ip. 你需要用服务器的ip启动它。

If nobody can solve this problem, then OWIN is useless to me. 如果没有人能解决这个问题,那么OWIN对我来说毫无用处。 "Switching back to IIS" “切换回IIS”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM