2017-04-05 9 views
-1

私は問題を抱えています.SSLをサポートするノードjsサーバーを設定することはできません。また、このsslを介して静的ファイルを提供することもできます。app.use (express.static(__ dirname + '/ public'))ファイルはhttps標準サーバーから配信されています。 これをやろうとしている人がいますか?sslと静的な埋め込み機能を持つnode.js

//require engines 
var express  = require('express'); 
var session  = require('express-session'); 
var bodyParser = require('body-parser') 

//init express engine 
var app = express(); 

//using 
app.use(bodyParser.json()); 
app.use(express.static(__dirname + '/public')); 

var activeport = process.env.PORT ? process.env.PORT : 4003; 

if (process.env.NODE_ENV === "production") { 

    var fs = require('fs'); 
    var https = require('https'); 

    var options = { 
     key: fs.readFileSync(global.appRoot + '/xxx.pem'), 
     cert: fs.readFileSync(global.appRoot + '/yyy.crt'), 
     passphrase: "123123", 
     requestCert: false, 
     rejectUnauthorized: false 
    }; 

    var server = https.createServer(options, app).listen(activeport, function() { 
     console.log('Server listening on port ' + activeport); 
    }); 
} 
else { 
    app.listen(activeport, function() { 
     console.log('Server listening on port ' + activeport); 
    }); 
} 
+0

はあなたが本番モードになっていることを確認していますか?あなたが実際にelseブロックにいるかもしれないようです – powerc9000

答えて

0

これを試してみてください:

const path = require('path'); // <--- Require this 
app.use(express.static(path.join(__dirname, '/dist'))); 
0

OK]をクリックして、それを手に入れました。私は私のホスティングプロバイダとしてのアズールを使用しています Becouseは、AzureがあなたのためのSSLサポートのすべてを世話をしているので、私は、専用のHTTPSサーバーの作成に必要ませんでした:

var server = https.createServer(options, app).listen(activeport, function() { 
    console.log('Server listening on port ' + activeport); 
}); 

私が行うために必要なすべてを私のweb.configを次のコードを追加することです - https urlへの永続的なリダイレクト。

<!-- Redirect all traffic to SSL --> 
    <rule name="Force HTTPS" enabled="true"> 
     <match url="(.*)" ignoreCase="false" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="off" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" /> 
    </rule> 

Referar:How do you force express on node.js in Azure Websites to use https?

関連する問題