【发布时间】:2016-10-10 01:20:38
【问题描述】:
我正在设置一个 Service Fabric 应用程序,其中包含:
- 一个 Nginx 实例作为前端(单实例,端口 80)
- 使用 Asp.net 核心编写的一些应用程序(1 个网站,一些 API 服务)(多个实例,动态端口)
- 用于地址解析的网关服务(单实例,端口 8081)
对于 nginx,我使用的解决方案是 Nuget package。
网关以及运行 .NET 核心应用程序的示例通常已采用here
.NET 核心团队本身建议将应用程序托管在 真实 Web 服务器后面,例如 nginx。 因此,我想以 nginx 实例作为入口点部署我的 Service Fabric 应用程序,该应用程序重定向到网关服务,该服务将为复制的无状态服务进行服务解析。
我的问题是关于我需要在 nginx.conf 中使用的地址来指向网关地址。在本地尝试时,我可以使用本地地址 127.0.0.1 并且它按预期工作,但是 如果在真实集群上我的 Nginx 和网关实例部署到不同的机器会发生什么?
这是我的应用程序清单:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="SFApplicationType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="NginxPoC_InstanceCount" DefaultValue="1" />
<Parameter Name="Gateway_InstanceCount" DefaultValue="1" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="NginxPoCPkg" ServiceManifestVersion="1.0.0" />
<Policies>
<RunAsPolicy CodePackageRef="Code" UserRef="Admin" EntryPointType="All" />
</Policies>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Gateway" ServiceManifestVersion="1.0.0" />
</ServiceManifestImport>
<DefaultServices>
<Service Name="NginxPoC">
<StatelessService ServiceTypeName="NginxPoCType" InstanceCount="[NginxPoC_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
<Service Name="Gateway">
<StatelessService ServiceTypeName="GatewayType" InstanceCount="[Gateway_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
<Principals>
<Users>
<User Name="Admin">
<MemberOf>
<SystemGroup Name="Administrators" />
</MemberOf>
</User>
</Users>
</Principals>
</ApplicationManifest>
这是我当前的 nginx.conf 文件:
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:8081;
}
}
2016 年 10 月 9 日更新
根据讨论中的要求,我创建了一个测试项目here。欢迎对项目做出任何贡献。
【问题讨论】:
-
创建问题,但是如果您正在为服务解析创建一个网关 - 为什么又需要 nginx 在前面,因为它也只是一个代理?我也经历过同样的想法,但选择不在前面有 nginx,所以我很好奇。
-
.NET 核心团队建议在 Kestrel 之前使用 IIS 或 nginx。此外,我还将获得 gzip、http2 等好处。
-
让我们知道这些建议是否来自公共链接。这是有道理的,也许从这些建议中还有其他值得一读的东西。
-
docs.asp.net/en/latest/fundamentals/… Quote: Kestrel 设计为在代理后运行(例如 IIS 或 Nginx),不应直接面向 Internet 部署。这里有一些提示:channel9.msdn.com/Series/aspnetmonsters/…
-
我编写了一个代理网关来避免使用 nginx,但基于此我将正确使用 nginx。但是然后使用 nginx 我不明白为什么你还想要网关项目。你不能告诉 nginx 转发到服务吗?
标签: nginx asp.net-core azure-service-fabric