配置nodejs节点:坏网关

时间:2016-10-25 09:10:43

标签: node.js nginx

我将我的节点服务器放在nginx后面。我这样工作,但我相信这不是最好的:

在bin / www

   server = https.createServer(config, app).listen(3210,'127.0.0.1');
   server.on('error', onError);
   server.on('listening', onListening);
app.js中的

    app.use(session({
       name: app_config.get('session.name'),
       secret: env.get("SESSION_SECRET"), 
       cookie: {httpOnly: true, secure: true },
       store: new MongoStore({ mongooseConnection: mongoose.connection,
       touchAfter: app_config.get('session.touchAfter') 
                      })
    }));

nginx,demo.server.com

   server {
      listen 0.0.0.0:443;
      server_name demo.server.com;
      access_log /var/log/nginx/demo.server.com.log;
      location / {
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header HOST $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass https://127.0.0.1:3210;
            proxy_redirect off;
      }
     }

这完美无缺。我的理解是节点服务器不需要处于https模式。我经过多次谷歌搜索后修改如下,当然它不起作用 - 我得到“502坏网关”。服务器已启动,netstat -a显示某些内容正在侦听3210端口。

在bin / www

   server = http.createServer(config, app).listen(3210,'127.0.0.1');
   server.on('error', onError);
   server.on('listening', onListening);
app.js中的

    app.use(session({
       name: app_config.get('session.name'),
       secret: env.get("SESSION_SECRET"), 
       cookie: {secure: true },
       store: new MongoStore({ mongooseConnection: mongoose.connection,
       touchAfter: app_config.get('session.touchAfter') 
                      })
    }));

nginx,demo.server.com

   server {
      listen 0.0.0.0:443;
      server_name demo.server.com;
      access_log /var/log/nginx/demo.server.com.log;
      location / {
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    
           proxy_set_header X-Forwarded-Proto $scheme; 
           proxy_set_header Host $http_host;
           proxy_set_header X-NginX-Proxy true;
           proxy_read_timeout 5m;
           proxy_connect_timeout 5m;
            proxy_pass http://127.0.0.1:3210;
            proxy_redirect off;
      }
     }

NGINX错误日志说:

2016/10/25 10:46:34 [error] 17278#0: *2 upstream prematurely closed    connection while reading response header  from upstream, client: xxxxx, server:  demo.server.com, request: "GET /itdemo HTTP/1.1", upstream: "http://127.0.0.1:3210/itdemo", host: "demo.server.com"

我做错了什么?感谢任何指针和帮助

1 个答案:

答案 0 :(得分:0)

对于普通的HTTP服务器,SELECT DAYOFYEAR(CURDATE()); 只接受一个参数,而不是两个:

createServer()