我已经编写了一个 Node JS 服务器,等待坐在服务器上。在理想的情况下,我想创建一个指向 Node 服务器的子域。我看过一些文章,允许您通过 v-host Apache 代理转发到特定端口/端口上的 Node 服务器。
示例:
<VirtualHost 109.74.199.47:80>
ServerAdmin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f6b6e7976216d7d6660614f7b676e7b6a777b7d6e6266636a216d6a" rel="noreferrer noopener nofollow">[email protected]</a>
ServerName thatextramile.be
ServerAlias www.thatextramile.be
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache/
然而,人们建议这不是最好的方法,因为 Apache 的进程将阻塞,直到 Node 响应为止。另外,ajax 请求似乎也有问题。是否有另一种方法可以在不使用 Apache 的情况下将 sum-domain 指向 Node JS?如果 Node 位于端口 x 上而 Apache 位于端口 80 和 443 上,会导致问题吗?他们会发生冲突吗?
最佳答案
试试这个
1.- Create subdomain directory and put to it your plesk subdomain rootdir.
2.- Put there your dist
3.- Choose and change the NODE.js port (In your env variables (in /server/config) and open it in Firewall access rules in Parallels plesk
4.- Go to your subdomain in parallels plesk and Enter web Server config
5.- In the aditional directives for http, put this:
RewriteEngine on
RewriteCond %{SERVER_NAME} yoursub.domain.com
RewriteCond %{SERVER_PORT} !8750 <-- CHOOSE YOUR PORT NUMBER AND CHANGE
RewriteRule ^/(.*) http://yoursub.domain.com:8750/$1 [P,R]
RewriteCond %{SERVER_PORT} 8750 <-- CHOOSE YOUR PORT NUMBER AND CHANGE
RewriteRule ^/(.*) http://yoursub.domain.com:8750/$1 [P,L] <-- CHOOSE YOUR PORT NUMBER AND CHANGE
然后重新启动apache。并尝试一下:)希望它有帮助并且不要错过任何东西
编辑关于node.js之前的apache是否有任何问题的答案。 -> 不适合我。 Apache 和 Node.js 一起运行得很好。至少对我来说是这样。
关于javascript - Node js 和 Apache 并行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30287146/