how to put nodejs and apache in the same port 80

前端 未结 6 1177
执笔经年
执笔经年 2020-12-04 17:04

I have to put nodejs in port 80, but apache is already using it. How can I put both (nodejs and apache) on the same port 80? I need it because in my university all the ports

6条回答
  •  再見小時候
    2020-12-04 17:29

    I found a cool gist Run apache and nodejs on port 80. did not try it yet but will do of course

    Step 1

    Get a VPS that offers 2 or more IP addresses.

    Step 2

    From the WHM cPanel, find the menu item Service Configuration, select Apache Configuration and then click on Reserved IPs Editor.

    Step 3

    Tick the IP address you DON'T WANT Apache to listen to, and write it down so you can use it in the next step. Click Save.

    Step 4

    Install Node.js, and create a server like this:

    var http = require('http');
    
    var server = http.createServer(function(req, res) {
      res.writeHead(200);
      res.end('Hello, world!');
    });
    
    server.listen(80, '111.111.111.111');
    

    Replacing 111.111.111.111 with the IP address you previously reserved from the WHM cPanel.

    Step 5

    Stop wasting your time and never listen to those telling you to use mod_rewrite to proxy Node.js again.

    Update:

    We can solve a problem in many different ways and IMHO, we should at least know each possible way

提交回复
热议问题