2016-04-29 53 views
4

因此,我繼承了一個運行在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不能夠返回數據。

回答

1

很多周圍挖後,我偶然發現了這個評論: https://unix.stackexchange.com/a/255404

因爲我在CentOS 7,禁用firewalld的伎倆我。我沒有意識到改變。從某種意義上說,joelnb在回答評論中檢查iptables的註釋是正確的方向(謝謝!)。請檢查您的操作系統的防火牆,並嘗試禁用它,看看它是否有助於解決問題。如果是的話,那麼你可以繼續爲你的端口配置一個規則。

爲CentOS 7,打開firewalld端口: centos 7 - open firewall port

我希望這可以幫助別人。

0

我懷疑你沒有Vagrantfile中的端口轉發設置,因爲如果我沒有/如果沒有在該端口上監聽的話,我會得到確切的錯誤。你的Vagrantfile看起來像下面那樣嗎? forwarded_port部分是重要的一點。

Vagrant.configure(2) do |config| 
    config.vm.box = "ubuntu/trusty64" 
    config.vm.network "forwarded_port", guest: 3001, host: 3001 
end 

否則可否請您發佈您的Vagrantfile,我會修改我的答案。

+0

嗨,我已經添加了我的流浪文件。我轉發了端口3000和3001,但目前只使用3001進行SSL。 – evkwan

+0

好的,虛擬機中'sudo iptables -L'的輸出是什麼?而且你也許希望檢查'vagrant up'的輸出 - 因爲你有端口auto_correct它可以分配不同的端口,如果在3001上有其他的監聽(儘管這是不太可能的)。 – joelnb

+0

因爲我只運行應用程序進行測試,所以我實際上禁用了vm上的iptables。 – evkwan

相關問題