日志调整
This commit is contained in:
parent
f508c531ed
commit
a3517d9d3a
@ -43,7 +43,7 @@ namespace FastGithub.Dns
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
this.dnsServer.Listen();
|
||||
this.logger.LogInformation("dns服务启用成功");
|
||||
this.logger.LogInformation("dns服务启动成功");
|
||||
this.dnsAddresses = this.SetNameServers(IPAddress.Loopback, this.options.Value.UpStream);
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using FastGithub.Scanner;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
@ -13,16 +14,21 @@ namespace FastGithub.ReverseProxy
|
||||
sealed class GithubDnsHttpHandler : DelegatingHandler
|
||||
{
|
||||
private readonly IGithubScanResults scanResults;
|
||||
private readonly ILogger logger;
|
||||
|
||||
/// <summary>
|
||||
/// Github的dns解析的httpHandler
|
||||
/// </summary>
|
||||
/// <param name="scanResults"></param>
|
||||
/// <param name="innerHandler"></param>
|
||||
public GithubDnsHttpHandler(IGithubScanResults scanResults, HttpMessageHandler innerHandler)
|
||||
public GithubDnsHttpHandler(
|
||||
IGithubScanResults scanResults,
|
||||
HttpMessageHandler innerHandler,
|
||||
ILogger logger)
|
||||
: base(innerHandler)
|
||||
{
|
||||
this.scanResults = scanResults;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -39,6 +45,7 @@ namespace FastGithub.ReverseProxy
|
||||
var address = this.scanResults.FindBestAddress(uri.Host);
|
||||
if (address != null)
|
||||
{
|
||||
this.logger.LogInformation($"使用{address}请求{uri.Host}");
|
||||
var builder = new UriBuilder(uri)
|
||||
{
|
||||
Host = address.ToString()
|
||||
|
||||
@ -5,23 +5,45 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace FastGithub
|
||||
{
|
||||
/// <summary>
|
||||
/// ListenOptions扩展
|
||||
/// Kestrel扩展
|
||||
/// </summary>
|
||||
public static class ListenOptionsHttpsExtensions
|
||||
public static class KestrelServerOptionsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用fastGihub的https
|
||||
/// 监听github的反向代理
|
||||
/// </summary>
|
||||
/// <param name="listenOptions"></param>
|
||||
/// <param name="kestrel"></param>
|
||||
/// <param name="caPublicCerPath"></param>
|
||||
/// <param name="caPrivateKeyPath"></param>
|
||||
/// <returns></returns>
|
||||
public static ListenOptions UseGithubHttps(this ListenOptions listenOptions, string caPublicCerPath, string caPrivateKeyPath)
|
||||
public static void ListenGithubReverseProxy(this KestrelServerOptions kestrel, string caPublicCerPath, string caPrivateKeyPath)
|
||||
{
|
||||
var loggerFactory = kestrel.ApplicationServices.GetRequiredService<ILoggerFactory>();
|
||||
var logger = loggerFactory.CreateLogger($"{nameof(FastGithub)}{nameof(ReverseProxy)}");
|
||||
TryInstallCaCert(caPublicCerPath, logger);
|
||||
|
||||
try
|
||||
{
|
||||
kestrel.ListenAnyIP(443, listen => listen.UseGithubHttps(caPublicCerPath, caPrivateKeyPath));
|
||||
logger.LogInformation("反向代理服务启动成功");
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.LogError($"无法开启反向代理功能:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 安装根证书
|
||||
/// </summary>
|
||||
/// <param name="caPublicCerPath"></param>
|
||||
/// <param name="logger"></param>
|
||||
private static void TryInstallCaCert(string caPublicCerPath, ILogger logger)
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
@ -38,12 +60,20 @@ namespace FastGithub
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var loggerFactory = listenOptions.ApplicationServices.GetRequiredService<LoggerFactory>();
|
||||
var logger = loggerFactory.CreateLogger($"{nameof(FastGithub)}{nameof(ReverseProxy)}");
|
||||
logger.LogError($"安装根证书{caPublicCerPath}失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用fastGihub的https
|
||||
/// </summary>
|
||||
/// <param name="listenOptions"></param>
|
||||
/// <param name="caPublicCerPath"></param>
|
||||
/// <param name="caPrivateKeyPath"></param>
|
||||
/// <returns></returns>
|
||||
private static ListenOptions UseGithubHttps(this ListenOptions listenOptions, string caPublicCerPath, string caPrivateKeyPath)
|
||||
{
|
||||
return listenOptions.UseHttps(https =>
|
||||
{
|
||||
var certs = new ConcurrentDictionary<string, X509Certificate2>();
|
||||
@ -1,5 +1,6 @@
|
||||
using FastGithub.Scanner;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Security;
|
||||
@ -14,6 +15,7 @@ namespace FastGithub.ReverseProxy
|
||||
sealed class NoneSniHttpClientFactory
|
||||
{
|
||||
private readonly IGithubScanResults githubScanResults;
|
||||
private readonly ILogger<NoneSniHttpClientFactory> logger;
|
||||
|
||||
/// <summary>
|
||||
/// 生命周期
|
||||
@ -35,9 +37,12 @@ namespace FastGithub.ReverseProxy
|
||||
/// 禁用tls sni的HttpClient工厂
|
||||
/// </summary>
|
||||
/// <param name="githubScanResults"></param>
|
||||
public NoneSniHttpClientFactory(IGithubScanResults githubScanResults)
|
||||
public NoneSniHttpClientFactory(
|
||||
IGithubScanResults githubScanResults,
|
||||
ILogger<NoneSniHttpClientFactory> logger)
|
||||
{
|
||||
this.githubScanResults = githubScanResults;
|
||||
this.logger = logger;
|
||||
this.lifeTimeHttpHandlerLazy = new Lazy<LifetimeHttpHandler>(this.CreateHttpHandler, true);
|
||||
}
|
||||
|
||||
@ -78,7 +83,7 @@ namespace FastGithub.ReverseProxy
|
||||
}
|
||||
};
|
||||
|
||||
var dnsHandler = new GithubDnsHttpHandler(this.githubScanResults, noneSniHandler);
|
||||
var dnsHandler = new GithubDnsHttpHandler(this.githubScanResults, noneSniHandler, this.logger);
|
||||
return new LifetimeHttpHandler(dnsHandler, this.lifeTime, this.OnHttpHandlerDeactivate);
|
||||
}
|
||||
|
||||
|
||||
@ -25,19 +25,16 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.domain.json.example">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.github.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="FastGithub_CA.cer">
|
||||
<None Update="FastGithub.cer">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="FastGithub_CA.key">
|
||||
<None Update="FastGithub.key">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="README.MD">
|
||||
|
||||
@ -43,15 +43,8 @@ namespace FastGithub
|
||||
})
|
||||
.ConfigureWebHostDefaults(web =>
|
||||
{
|
||||
web.Configure(app =>
|
||||
{
|
||||
app.UseGithubReverseProxy();
|
||||
});
|
||||
|
||||
web.UseKestrel(kestrel =>
|
||||
{
|
||||
kestrel.ListenAnyIP(443, listen => listen.UseGithubHttps("FastGithub_CA.cer", "FastGithub_CA.key"));
|
||||
});
|
||||
web.Configure(app => app.UseGithubReverseProxy());
|
||||
web.UseKestrel(kestrel => kestrel.ListenGithubReverseProxy("FastGithub.cer", "FastGithub.key"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development",
|
||||
//"Logging__LogLevel__Default": "Trace"
|
||||
"Logging__LogLevel__Default": "Trace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ github定制版的dns服务,解析github最优的ip
|
||||
|
||||
### 安装根证书
|
||||
默认开启github反向代理功能,开启之后dns返回github的ip指向FastGithub自身。
|
||||
需要在浏览器所在的设备安装FastGithub_CA.cer到`将所有的证书都放入下载存储\受信任的根证书颁发机构`
|
||||
需要在浏览器所在的设备安装FastGithub.cer到`将所有的证书都放入下载存储\受信任的根证书颁发机构`
|
||||
|
||||
### 本机使用
|
||||
* 运行FastGithub程序,本机的网络适配器的dns会自动变成127.0.0.1
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
{
|
||||
"Lookup": { // ip查找
|
||||
"Domains": [ // 查找的域名,下面是要加速的域名
|
||||
"domain.com",
|
||||
"xx.domain.com",
|
||||
"yy.domain.com"
|
||||
]
|
||||
},
|
||||
"Scan": { // 扫描规则
|
||||
"HttpsScan": {
|
||||
"Rules": { // 域名扫描规则,缺失的域名,将默认HEAD请求到域名的根路径
|
||||
"xx.domain.com": {
|
||||
"Method": "HEAD",
|
||||
"Path": "/xx/"
|
||||
},
|
||||
"yy.domain.com": {
|
||||
"Method": "HEAD",
|
||||
"Path": "/yy/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,6 @@
|
||||
"8.8.8.8",
|
||||
"223.5.5.5",
|
||||
"123.125.81.6",
|
||||
"180.76.76.76",
|
||||
"119.29.29.29",
|
||||
"208.67.220.220",
|
||||
"114.114.114.114"
|
||||
@ -43,8 +42,10 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Yarp": "Warning",
|
||||
"System": "Warning",
|
||||
"Microsoft": "Warning"
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.AspNetCore.Server.Kestrel": "Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user