swagger.net 使用nginx 代理时出现端口号导致出错
1:当我们通过nginx代理访问时,由于nginx配置了映射到的一个站点为端口为127.0.0.1:6201,导致访问swagger接口时出现增加端口号,如下截图,这样就导致整个swagger无法使用。
2:这个问题网上找了很多没找到方法,主要是自己英语太差了,没注意看到注释内容,可以配置一个固定的url地址用于 代理/负载均衡 。
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.IncludeXmlComments(GetXmlCommentsPath());
c.IncludeXmlComments(System.String.Format(@"{0}\bin\KJ.Model.XML", System.AppDomain.CurrentDomain.BaseDirectory));
// By default, the service root url is inferred from the request used to access the docs.
// However, there may be situations (e.g. proxy and load-balanced environments) where this does not
// resolve correctly. You can workaround this by providing your own code to determine the root URL.
//
if (IsRelease())
{
c.RootUrl(req => "https://xxx");
}