• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

nodejs port forwarding 처리

23 Apr 2019

Reading time ~1 minute

nodejs port forwarding 처리

https를 설정하고 나니, 기존 80 포트로 요청이 있을 경우, 443으로 redirect 하는 방법을 찾아보았다.

구글을 확인해보니, 다음과 같이 쉽게 처리 할 수 있었다.

// Redirect from http port 80 to https
var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
    res.end();
}).listen(80);

구글과 함께면 뭐든 쉽다.

참조 링크

  • Automatic HTTPS connection/redirect with node.js/express


portnodejs Share Tweet +1