【发布时间】:2021-08-19 16:54:48
【问题描述】:
我是 Nginx 的新手,我需要您的帮助/建议来解决以下问题。
我已将 Nginx 配置为 Windows Server 2012 r2 上的反向代理,并尝试在向 Nginx 发出请求时将调用路由到我的后端服务器“SERVERA”。
我的要求是,我需要将客户端证书传递给 Nginx 服务器,如果证书有效,则将调用路由到后端服务器“SERVERA”,否则它应该拒绝 Nginx 的调用。
我已经对 Nginx 服务器上的配置文件进行了如下更改,以配置客户端认证验证。
server {
listen 443 ssl;
server_name localhost;
ssl_certificate "C:/NewCert/server.crt";
ssl_certificate_key "C:/NewCert/server.key";
ssl_client_certificate "C:/NewCert/ca.crt";
ssl_verify_client on;
location / {
root html;
index index.html index.htm;
proxy_pass https://SERVERA/MyWebService;
}
location /MyWebService {
root html;
index index.html index.htm;
proxy_pass https://SERVERA/MyWebService;
}
}
我已经生成了下面帖子中所述的客户端和服务器证书,并将其用于 Nginx 服务器配置 "http://nategood.com/client-side-certificate-authentication-in-ngi"
在 Nginx 服务器上进行上述配置更改后,每当我尝试浏览服务时,我都会收到“400 Bad request” "https://localhost/MyWebService"
当我使用客户端证书从客户端调用 Nginx 服务器时,出现以下错误。
"{System.Net.WebException:错误:SecureChannelFailure(对 SSPI 的调用 失败,请参阅内部异常。)---> System.Security.Authentication.AuthenticationException:对 SSPI 的调用 失败,请参阅内部异常。 ---> Mono.Btls.MonoBtlsException:系统调用 在 Mono.Btls.MonoBtlsContext.ProcessHandshake () [0x00038] 中 :0 在 Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncOperationStatus 状态)[0x0003e] 在 :0 在(包装 远程调用检查) Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.Net.Security.AsyncOperationStatus) 在 Mono.Net.Security.AsyncHandshakeRequest.Run (Mono.Net.Security.AsyncOperationStatus 状态) [0x00006] in :0 在 Mono.Net.Security.AsyncProtocolRequest+d__24.MoveNext ()"
下面是我的客户端代码
namespace Test
{
class SomeTest
{
public void SomeMethod()
{
try
{
string urlString = @"https://SERVERA/MyWebService";
MyWebClient obj = new MyWebClient();
obj.UploadData(urlString, new byte[2]);
}
catch (Exception ex)
{
string st = ex.Message;
}
}
}
class MyWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
System.Security.Cryptography.X509Certificates.X509Certificate x509Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate(@"/storage/emulated/0/nginx.crt");
request.ClientCertificates.Add(x509Certificate);
request.Method = "POST";
return request;
}
}
}
非常感谢任何帮助/建议。
谢谢, 维诺德
【问题讨论】:
-
我在错误日志中收到以下消息。客户端在读取客户端请求标头时未发送任何必需的 SSL 证书,客户端:x.x.x.x,服务器:localhost,请求:“GET /favicon.ico HTTP/1.1”,主机:“y.y.y.y”,引用者:“y.y.y.y”