因此,我繼承了一個運行在Vagrant框中的Nodes.js應用程序。通過SSL/TLS連接訪問Vagrant上的Node.js應用程序
我將應用程序綁定到「0.0.0.0」,並且它在securekey文件夾中有自己的server.key和certs。
var https = require('https');
var fs = require('fs');
var ssl_options = {
key: fs.readFileSync('./securekey/server.key'),
cert: fs.readFileSync('./securekey/server.crt'),
ca: fs.readFileSync('./securekey/ca.crt')
};
https.createServer(ssl_options, app).listen(3001, '0.0.0.0');
當我運行應用程序,我希望能夠通過URL https://localhost:3001
訪問它在我的Windows(流浪是我的Windows PC上運行)瀏覽器,但我得到「安全連接失敗」在Mozilla上。
我沒有使用Cygwin嘗試這個在Windows PC:
$ openssl s_client -host 127.0.0.1 -port 3001
CONNECTED(00000003)
write:errno=104
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 316 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1461923745
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
而且
$ curl -v -k 'https://localhost:3001'
* STATE: INIT => CONNECT handle 0x6000574a0; line 1103 (connection #-5000)
* Rebuilt URL to: https://localhost:3001/
* Added connection 0. The cache now contains 1 members
* Trying 127.0.0.1...
* STATE: CONNECT => WAITCONNECT handle 0x6000574a0; line 1156 (connection #0)
* Connected to localhost (127.0.0.1) port 3001 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x6000574a0; line 1253 (connection #0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* STATE: SENDPROTOCONNECT => PROTOCONNECT handle 0x6000574a0; line 1267 (connection #0)
* Unknown SSL protocol error in connection to localhost:3001
* Curl_done
* Closing connection 0
* The cache now contains 0 members
curl: (35) Unknown SSL protocol error in connection to localhost:3001
但是當流浪VM終端上運行這些命令返回的成功連接!
我需要做些什麼來讓我的Windows PC /瀏覽器接受應用程序的證書,以便我可以從Mozilla Firefox訪問應用程序?既然它已經有server.key和certs,當然我不需要爲應用程序再次生成我自己的密鑰?
編輯: 這裏是我的流浪文件:
Vagrant.configure(2) do |config|
config.vm.box = "centos7"
config.vm.network "forwarded_port", guest: 3000, host: 3000, auto_correct: true
config.vm.network "forwarded_port", guest: 3001, host: 3001, auto_correct: true
end
我只得到了端口轉發configs..the其餘默認。
而當應用程序是在流浪運行參數,netstat顯示該端口監聽連接
$ netstat -an | grep 3001
TCP 0.0.0.0:3001 0.0.0.0:0 LISTENING
當我在瀏覽器上訪問https://localhost:3001,我看到:
netstat -an | grep 3001
TCP 0.0.0.0:3001 0.0.0.0:0 LISTENING
TCP 127.0.0.1:3001 127.0.0.1:49651 ESTABLISHED
TCP 127.0.0.1:49651 127.0.0.1:3001 ESTABLISHED
似乎像端口連接沒問題,但是vm不能夠返回數據。
嗨,我已經添加了我的流浪文件。我轉發了端口3000和3001,但目前只使用3001進行SSL。 – evkwan
好的,虛擬機中'sudo iptables -L'的輸出是什麼?而且你也許希望檢查'vagrant up'的輸出 - 因爲你有端口auto_correct它可以分配不同的端口,如果在3001上有其他的監聽(儘管這是不太可能的)。 – joelnb
因爲我只運行應用程序進行測試,所以我實際上禁用了vm上的iptables。 – evkwan