Search code examples
azurenancy

Nancy Self Host in Azure Worker Role


I have an azure worker role deployed which runs a a few scheduled tasks as part of an integration system. I am trying to expose an http endpoint which will provide some administrative functions so I can control aspects of the worker role remotely.

I have the work role and up running the only problem is that I am not able to access http endpoint from the internet.

I have confirmed that the nancy server is running since when I remote onto the VM I am able to connect using the local ip address.

The role config is as follows:

<ServiceDefinition name="Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
<WorkerRole name="Host.Azure" vmsize="Small">
<ConfigurationSettings>
  <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
</ConfigurationSettings>
<Startup>
  <Task commandLine="mount.cmd" executionContext="limited" taskType="background">
  </Task>
</Startup>
<Endpoints>
  <InputEndpoint name="http" protocol="http" port="80" localPort="80" />
</Endpoints>
<LocalResources>
</LocalResources>
<Imports>
  <Import moduleName="RemoteAccess" />
  <Import moduleName="RemoteForwarder" />
</Imports>
</WorkerRole>
</ServiceDefinition>

I am creating the nancy url as follows:

var endpointName = "http";
var instance = RoleEnvironment.CurrentRoleInstance;
var internalEndpoint = instance.InstanceEndpoints[endpointName];
var uri = new Uri($"{internalEndpoint.Protocol}://{internalEndpoint.IPEndpoint}");
return new NancyUri {Value = uri};

Is there something else which I need t o do to get this working?


Solution

  • It had to do with the windows url acl config. I thought because I was supplying the local ip to the nancy host it would work, but I had to add an entry to the http acl in the end.

    The nancy url is being built up like this

    var uri = new Uri("http://localhost:80");
    return new NancyUri {Value = uri};
    

    I setup a task to run the following command

    netsh http add urlacl url="http://+:80/" user="Everyone"
    

    Which reference in the csdef file as follows:

    <Task commandLine="network.cmd" executionContext="elevated" taskType="background"></Task>