Node.js Server running from a sub folder

后端 未结 3 2012
夕颜
夕颜 2021-02-07 18:06

So I\'m pretty late to the Node.js party. Mainly because nobody invited me... Thanks. That said, I\'m starting to work it out. I have come from an ASP classic b

3条回答
  •  深忆病人
    2021-02-07 18:57

    You have tons of options, but none of them will allow you to use port 80 for your Node application on the same server as Apache+PHP without proxying.

    Your two best options are the following:

    1) set up a new subdomain - create a new DNS entry for node.newsite.dev, and direct that subdomain to a completely different IP, on a different server (though, technically, you can set up two IPs on the same server, see here), then node can be run on port 80 on its separate server

    2) have Apache run on port 80 on /path/to/apache/publicdir/newsite.dev, and have node run on port 1337 on /path/to/node/application/newsite.dev, then you can access your apache files at http://newsite.dev, and your node application at http://newsite.dev:1337

    Whatever you do, don't put your node application in a subdirectory that Apache knows about, unless you want to serve those .js files publicly.

    EDIT TO RESPOND TO YOUR EDIT: If your goal is to move to Node exclusively and eventually turn off Apache+PHP, then your best bet is to use a subdomain. The downside is that you'll have to use fully qualified links everywhere. The upside is that when you feel enough of your application is in node, you can do a find/replace (#//(www\.)?newsite.dev#, '//apache.newsite.dev') and (#//node.newsite.dev#, '//newsite.dev'), and then when you're totally off of Apache, just shut it down.

提交回复
热议问题