Node.js Server running from a sub folder

后端 未结 3 1369
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 18:41

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 19:03

    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.

    0 讨论(0)
  • 2021-02-07 19:04

    You are asking to create a virtual directory and yes you can setup Node.js with PHP but you must do a little reading.

    A virtual directory is a website that lives within a folder like www.yourwebsite/myotherwebsite

    Here's how to set that up in Apache.

    http://httpd.apache.org/docs/current/vhosts/examples.html

    Here's how to set that up in IIS.

    http://technet.microsoft.com/en-us/library/cc771804(v=ws.10).aspx

    You would then need to hook up Node.js with Apache or IIS. Here's more instructions.

    Linux: How can I implement virtual directories with node.js and express?

    Windows: http://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx

    0 讨论(0)
  • 2021-02-07 19:06

    Only one server can listen on a port at a time. You cannot have Node.js and some other server on the same port.

    The best thing to do is set up a different hostname for your other server.

    If you cannot do that, the standard way is to proxy requests from one server to the other. This is relatively easy to do, but you didn't specify what server you're running, so it is impossible to be more specific.

    0 讨论(0)
提交回复
热议问题