我对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错误的请求” “ 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 at(包装) 带检查的远程调用) Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.Net.Security.AsyncOperationStatus) 在Mono.Net.Security.AsyncHandshakeRequest.Run (Mono.Net.Security.AsyncOperationStatus状态)在[0x00006]中 :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;
}
}
}
非常感谢您的帮助/建议。
谢谢, Vinod