繁体   English   中英

NGINX:将所有对我的本地主机端口的请求重定向到https / SSL

[英]NGINX: Redirect all requests to my localhost port to https/SSL

我有一个运行在localhost:8080上的NodeJS服务器。 这是HTTPS服务器,而不是HTTP。

因此,该网站在访问http://localhost8080时无法正常工作,只能与https://localhost:8080

我想使用NGINX将所有来自localhost:8080/whatever流量重定向到https://localhost:8080/whatever

我试过了:

server {
    listen 8080;
    server_name 127.0.0.1;
    return 301 https://$server_name$request_uri;
}

无济于事-也许Nginx正在以某种方式被我的Node / ExpressJS服务器覆盖?

app.configure(function () {
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser());
  app.configure('production', function () {
    app.use (function (req, res, next) {
      var schema = (req.headers['x-forwarded-proto'] || '').toLowerCase();
      if (schema === 'https') {
        next();
      } else {
        res.redirect('https://' + req.headers.host + req.url);
      }
    });
  });
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
  app.use(express.favicon(__dirname + '/public/favicon.ico'));
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM