2016-08-11 12 views
0

バックエンドではnodejs + expressを、フロントエンドではangularjsをビルドしてnginxで実行します。 nginxのセットアップnginx ssl nodejs + express socket.io angularjs

server { 
     listen 82; 
     server_name example.com www.example.com; 
     access_log /var/log/nginx/access.log; 
     error_log /var/log/nginx/error.log; 

     location/{ 
     rewrite ^ https://$server_name$request_uri? permanent; 
     } 

    } 

ため、この私のセットアップと魔法のように滑らかSSL

server { 
     listen 443; 
     ssl on; 
     access_log /var/log/nginx/access.log; 
     error_log /var/log/nginx/error.log; 
     ssl_certificate /home/ubuntu/config.com.ssl/ssl.crt; 
     ssl_certificate_key /home/ubuntu/config.com.ssl/ssl.key; 
     server_name example.com www.example.com; 

     location/{ 
      proxy_pass https://someIP:8085; 

      proxy_http_version 1.1; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection 'upgrade'; 
      proxy_set_header Host $host; 
      proxy_cache_bypass $http_upgrade; 
     } 


     location ~ ^/(scripts.*js|styles|images) { 
      gzip_static on; 
      expires 1y; 
      add_header Cache-Control public; 
      add_header ETag ""; 

      break; 
     } 
     location /socket.io { 
      proxy_pass https://someIP:3001; 
      #proxy_http_version 1.1; 
      #proxy_set_header Upgrade $http_upgrade; 
      #proxy_set_header Connection 'upgrade'; 
      #proxy_set_header Host $host; 
      #proxy_cache_bypass $http_upgrade; 
     } 

     location /api { 
      proxy_pass https://someIP:3001; 

      proxy_http_version 1.1; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection 'upgrade'; 
      proxy_set_header Host $host; 
      proxy_cache_bypass $http_upgrade; 
     } 

     location /public { 
      proxy_pass https://someIP:3001; 

      proxy_http_version 1.1; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection 'upgrade'; 
      proxy_set_header Host $host; 
      proxy_cache_bypass $http_upgrade; 
     } 
} 

ため、これ

var app = require('../app'); 
    var debug = require('debug')('tlevi:server'); 
    var fs = require('fs'); 
    var http = require('http'); 
    var https = require('https') 
    var options = { 
     key: fs.readFileSync('./configssl/ssl.key'), 
     cert: fs.readFileSync('./configssl/ssl.crt') 
    } 
    /** 
    * Get port from environment and store in Express. 
    */ 

    var port = normalizePort(process.env.PORT || '3001'); 
    app.set('port', port); 

    /** 
    * Create HTTP server. 
    */ 

    //var server = http.createServer(app); 
    var server = https.createServer(options, app); 
    /**var server = https.createServer(app, options, (req, res) => { 
    res.writeHead(200); 
    res.end('hello world\n ssl'); 
    }).listen(3000); 
    */ 
    var io = app.io; 
    io.attach(server); 

    /** 
    * Listen on provided port, on all network interfaces. 
    */ 

    server.listen(port); 
    server.on('error', onError); 
    server.on('listening', onListening); 

サーバーの実行などのバックエンド私のセットアップサーバー上のこのルート443が、クライアント上サイドは502の悪いゲートウェイを持っています(しかしsslはうまく走ります)。クライアントはいつでも実行できますが、クライアントからサーバーにAPIを送信できます。

私は逃した?

答えて

0

うわー後半の応答:listen 82;listen 80;

デフォルトのHTTPリクエスト・ポートはSSLが機能している理由を説明するだろう80ですでなければなりません。