1

我目前拥有一个具有Web角色的Azure云服务(因此它是安装有IIS的虚拟机)。此Web角色当前运行一个独特的Web应用程序(WebAPI项目)。在同一个Azure WebRole(云服务)上运行多个应用程序

我想要做的是创建一个新的Web应用程序,但我需要它运行在同一个Web角色(即同一虚拟机上的两个应用程序)上以降低成本。我知道这是可能的(两个Web应用程序将运行在同一个IIS实例上,同一台计算机上,具有不同的端口),但我找不到有关如何使用最新版本的Azure SDK执行操作的资源。

我发现很大的资源:

但都有点老了(< = 2013)和不适用了。

我目前使用的是Azure SDK 2.6。我试着改变我的ccproj文件(云服务项目文件),因此两者的WebAPI项目共享相同的RoleName

<ProjectReference Include="..\MyProject1.csproj"> 
    <Name>Website</Name> 
    <Project>{...}</Project> 
    <Private>True</Private> 
    <RoleType>Web</RoleType> 
    <RoleName>MyRole</RoleName> 
</ProjectReference> 
<ProjectReference Include="..\MyProject2.csproj"> 
    <Name>Website</Name> 
    <Project>{...}</Project> 
    <Private>True</Private> 
    <RoleType>Web</RoleType> 
    <RoleName>MyRole</RoleName> 
</ProjectReference> 

这是不行的,在Visual Studio中我的项目的“角色”节点显示错误("no project associated [project 2 name])。

我还试图修改我的ServiceDefinition.csdef文件:

<WebRole name="xxxx.Frontend.Azure" vmsize="Small"> 
    <Sites> 
     <Site name="Web"> 
      <Bindings> 
       <Binding name="Endpoint1" endpointName="Endpoint1" /> 
      </Bindings> 
     </Site> 
     <Site name="AnotherWeb" physicalDirectory="foo"> 
      <Bindings> 
       <Binding name="Endpoint2" endpointName="Endpoint2" /> 
      </Bindings> 
     </Site> 
    </Sites> 
    <Endpoints> 
     <InputEndpoint name="Endpoint1" protocol="http" port="8080" /> 
     <InputEndpoint name="Endpoint2" protocol="http" port="8090" /> 
    </Endpoints> 
</WebRole> 

没有任何运气。

我该如何继续?


编辑:

下面是与修改多个站点我目前csdef文件支持:

<?xml version="1.0" encoding="utf-8"?> 
<ServiceDefinition name="AzureCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6"> 
    <WebRole name="XXX.YYY" vmsize="Small"> 
    <Sites> 
     <Site name="Web"> 
     <Bindings> 
      <Binding name="Endpoint1" endpointName="Endpoint1" /> 
     </Bindings> 
     </Site> 
    </Sites> 
    <Endpoints> 
     <InputEndpoint name="Endpoint1" protocol="http" port="80" /> 
    </Endpoints> 
    <Imports> 
     <Import moduleName="RemoteAccess" /> 
    </Imports> 
    </WebRole> 
    <WebRole name="XXX.ZZZ" vmsize="Small"> 
    <Sites> 
     <Site name="Web"> 
     <Bindings> 
      <Binding name="Endpoint1" endpointName="Endpoint1" /> 
     </Bindings> 
     </Site> 
     <Site name="ZZZ" physicalDirectory="..\..\..\XXX.ZZZ\azure.publish"> 
     <Bindings> 
      <Binding name="Endpoint2" endpointName="Endpoint2" /> 
     </Bindings> 
     </Site> 
    </Sites> 
    <Endpoints> 
     <InputEndpoint name="Endpoint1" protocol="http" port="8081" /> 
     <InputEndpoint name="Endpoint2" protocol="http" port="8090" /> 
    </Endpoints> 
    <Imports> 
     <Import moduleName="RemoteAccess" /> 
    </Imports> 
    </WebRole> 
</ServiceDefinition> 

回答

3

我认为你在csdef文件更改的正确轨道上,以及ccproj更改的错误轨道。因此,摆脱你的第二个ProjectReference,因为你只需要在一天结束时使用一个WebRole。

应该在ccproj文件做的是添加这样一行:

<MSBuild Projects="..\MyProject2\MyProject2.csproj" ContinueOnError="false" Targets="PublishToFileSystem" Properties="Configuration=$(Configuration);PublishDestination=..\Publish\MyProject2\;AutoParameterizationWebConfigConnectionStrings=False" /> 

显然有假的路径,但最重要的是,你要确保该路径的csproj文件是有效的,并确保PublishDestination路径与您在csdef文件中为该站点指定的PhysicalDirectory路径匹配,并且请注意PhysicalDirectory路径和PublishDestination路径相对于同一位置是而不是。例如,我们保持一个“发布”目录中的解决方案的根,所以对我们的PublishDestination看起来像

..\Publish\MyProject2\ 

和physicalDirectory看起来像

..\..\..\Publish\MyProject2 

你的端点配置看起来是正确的,但如果作用是不能远程访问,请确保您的csdef文件有终点的线路:

<Endpoints> 
     <InputEndpoint name="MyProject1Endpoint" protocol="http" port="80" /> 
     <InputEndpoint name="MyProject2Endpoint" protocol="http" port="8080" /> 
    </Endpoints> 

...与对应于每个站点的endpointName一个“名字”:

<Sites> 
     <Site name="MyProject1Site" physicalDirectory="..\..\..\MyProject1"> 
      <Bindings> 
       <Binding name="MyProject1Binding" endpointName="MyProject1Endpoint" /> 
      </Bindings> 
     </Site> 
     <Site name="MyProject2Site" physicalDirectory="..\..\..\Publish\MyProject2"> 
      <Bindings> 
       <Binding name="MyProject2Binding" endpointName="MyProject2Endpoint" /> 
      </Bindings> 
     </Site> 
    </Sites> 

这是假设您希望每个站点可以在托管的同一端口上公开访问。如果出于某种原因,MyProject2在端口8081上本地运行,那么您需要将localPort="8081"添加到该InputEndpoint。

+0

谢谢,这使我在正确的轨道(我认为)。我仍然需要解决一些问题,但这听起来很有前途 – ken2k

+0

嗯,我成功地将我的两个应用程序部署在同一个Web角色上。不幸的是,只有其中一个通过互联网可用(我试图达到另一个时出现超时)。我已经远程连接到虚拟机(使用RDP),我可以看到两个应用程序都正确部署/运行,并且都可以在本地访问。所以我假设一个应用程序有一些网络配置问题,在通过Internet访问时没有响应。任何想法?谢谢 – ken2k

+0

本地可访问的角色,但不是远程的,它必须是端点配置问题。您的原始问题中的Endpoint配置看起来是正确的,但我仍然在回答中添加了一些示例配置行。希望能帮助到你! –

0

如果您可以部署应用程序作为Azure的Web应用程序,而不是,我会极力推荐它。它旨在很好地处理这种情况。您可以使用您需要的许多服务器实例创建应用服务计划,然后多个应用程序共享该组服务器。

+0

不幸的是,我不能轻易改变应用程序的构建方式,所以我必须坚持使用云服务。我确信有一个解决方案,但是(作为一个web角色是一个简单的虚拟机与IIS中) – ken2k

相关问题