无法访问Owin自托管RESTAPI - 部署到AWS EC2 - 2012的Windows R2 [英] Unable to Access Owin Self hosted RestApi - Deployed to AWS EC2 - Windows 2012 R2

查看:638
本文介绍了无法访问Owin自托管RESTAPI - 部署到AWS EC2 - 2012的Windows R2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是托管RESTAPI code样品的自我,我有OWIN创建。
这是工作在我的本地机器。

Following is the sample self hosting RestApi code, i have created with OWIN. It is working in my local machine.

我主持它AWS-EC2,并开始以管理员身份。

i have hosted it in aws-ec2, and started as administrator.

我能够从实例中访问RESTAPI(使用Chrome / IE)提供localhost作为URL。

I am able to access the RestApi from inside the instance (using chrome/IE) giving localhost as url.

但得到一个错误的请求无效的主机名,当我与实例的公共DNS(实例的浏览器内运行)替换本地主机。

But getting a Bad request invalid hostname, when i replace the localhost with public DNS of Instance (running within Instance's browser).

当我试图从实例浏览器之外,从我的本地机器(浏览器/邮递员),它返回状态0。访问RESTAPI

when i tried to access the RestApi from outside the instance browser from my local machine (browser/postman), it is returning status 0.

复制低于code。

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" }
                   };
    }
}

我创建了一个Windows 2012 R2 - AWS EC2实例

I have created a Windows 2012 R2 - AWS EC2 instance.

配置实例:


  1. 要允许入站和出站的所有流量。

  2. 打开的所有端口。

  3. 我已经禁用Windows防火墙

  4. 我试图从我的本地机器CMD ping到DNS名称,它是成功的。

  5. 的WebAPI使用,端口号 - 65435(临时端口)

  6. Owin版本 - 5.2.3.0,.NET版本 - 4.5(4.5.2安装在EC2实例)

  7. 改变了本地主机,在code到公共DNS(同样的问题仍然存在)和IP地址(抛出一个异常 - 异常已被调用的目标引发异常)

请帮我配置此!!

推荐答案

您已经开始了 Web应用程序在localhost:

You're starting the WebApp on localhost:

的http://本地主机:65435

它开始在环回适配器,而不是你是从外面试图访问实际的以太网适配器。您需要与服务器的IP启动它。

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.

这篇关于无法访问Owin自托管RESTAPI - 部署到AWS EC2 - 2012的Windows R2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆