NodeJS HTTP - listen on other port than 80

后端 未结 6 877
情歌与酒
情歌与酒 2021-01-12 00:21

I am running XAMPP on Windows to host an Apache server on port 80. Now I\'m trying to have a NodeJS script running in the background but the problem is that it can only list

6条回答
  •  广开言路
    2021-01-12 01:11

    This is same scenario as using NodeJs in a Shared Hosting. I have written a blogpost about it here

    Let me give an excerpt.

    1. Just run the NodeJS server at let's say 8080 port.

    2. Now, let's say your Apache serves at http://example.com, create a folder in your public_html or www. let's say the name is server. So, your new folder path is http://example.com/server

    3. create a .htaccess file in the server folder
    4. add the following lines,

      RewriteEngine On
      RewriteRule ^$ http://127.0.0.1:8080/ [P,L] #which is your node server ip:port
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ http://127.0.0.1:8080/$1 [P,L] #same ip:port
      

    This will redirect all the requests from http://example.com/server to your Node server.

提交回复
热议问题