2016-08-11 4 views
0

ich habe nodejs + express auf backend und angularjs auf fronted erstellen und unter nginx laufen lassen. dies mein Setup für nginxsetup 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; 
     } 

    } 

und diese Route 443 für 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; 
     } 
} 

und auf Back-End-i-Setup-Server wie dieser Lauf

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); 

Server wie Charme glatt, aber auf dem Client Seite bekam 502 schlechtes Gateway (aber ssl gut laufen). Manchmal kann der Client laufen, aber er kann die API vom Client zum Server rufen.

was habe ich verpasst?

Antwort

0

Wow späte Antwort: listen 82; sollte listen 80;

Standard-HTTP-Anfrage-Port ist 80. Das würde erklären, warum ssl funktioniert.