2010-11-23 7 views
1

node.js 앱에서 로컬로 호스팅 된 nginx 서버로 기본 SSL 연결을 만들려고합니다. 클라이언트의 자격 증명을 보내는 것도 포함됩니다. "보안"이벤트에서 "verifyPeer"를 호출하면 성공한 것처럼 악수가 많이 발생하는 것 같습니다. 그러나 서버는 400 응답 만 계속 응답합니다. 내가 명령 줄에 곱슬 같은 요청을 한 경우node.js 및 nginx SSL 핸드 셰이크 실패

, 내가 기대하는 것을 다시 얻을 :

curl -v -E curl-test.crt --cacert ca.crt https://internal.url:7443/some.file 

"컬 - test.crt는"함께 클라이언트 키와 인증서를 연결하여 만들었습니다.

: 여기

global.util = require('util'); 

var fs = require('fs'), 
    http = require('http'), 
    crypto = require('crypto'); 

var clientCert = fs.readFileSync("tmp/cert.crt", 'ascii'), 
    clientKey = fs.readFileSync("tmp/key.key", 'ascii'), 
    caCert = fs.readFileSync("tmp/ca.crt", 'ascii'); 
var credentials = crypto.createCredentials({"key": clientKey, "cert": clientCert, "ca": caCert}); 

var client = http.createClient(7443, "internal.url", true, credentials); 

client.addListener("secure", function() { 
    if (!client.verifyPeer()) { 
    throw new Exception("Could not verify peer"); 
    } 
}); 

var request = client.request('GET', '/some.file', {}); 

request.on('response', function(response) { 
    response.on('data', function(body) { 
    util.log("body: " + body); 
    }); 
}); 

request.end(); 

그리고 "some.file"로 변경됩니다 내가 상관없이 얻을 응답입니다 : 여기

는 실패를 얻을 필요 Node.js를 코드의 작은 비트가

디버깅에 어떤 도움이나 해결이 문제

body: <html> 
<head><title>400 Bad Request</title></head> 
<body bgcolor="white"> 
<center><h1>400 Bad Request</h1></center> 
<hr><center>nginx/0.6.32</center> 
</body> 
</html> 
은 환상적 일 것

답변

4

당신은 당신의 nginx 오류 로그에이 메시지를 받고 있습니까?

2010/11/23 17:51:59 [info] 13221#0: *1 client sent HTTP/1.1 request without "Host" header while reading client request headers, client: 127.0.0.1, server: testme.local, request: "GET /some.file HTTP/1.1" 

그렇다면, 당신은 단순히 같이 귀하의 GET 요청에 '호스트'헤더를 추가하여 문제를 해결할 수 :

var request = client.request('GET', '/some.file', {'Host':'internal.url'}); 

이 nginx를 것 같은데

이 호스트 헤더를 원하고 노드를 전송하지 않습니다 기본적으로. 아마도 올바른 헤더 값을 기본값으로 사용하도록 nginx를 구성하는 방법이있을 것입니다.

희망 하시겠습니까?

+0

당신은 그 주 남자입니다! 로그 파일 (어쩌면 로그 설정)에 나열된 오류 메시지가 표시되지 않았지만 어쨌든 호스트 설정을 시도 했으므로 실제로 트릭을 수행했습니다. 고마워요! – Gus

관련 문제