2

I have written a Node JS server waiting to sit on a server. In an ideal world, I'd like to create a sub-domain which points to the Node server. I have seen articles that allow you to v-host Apache to proxy forward to the node server on a specific port / port.

Example:

<VirtualHost 109.74.199.47:80>
ServerAdmin [email protected]
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/

People are suggesting however, that this isn't the best method as Apache's process will block until node has responded. Also it seems to be problematic with ajax requests.

Is there another way to point a sum-domain to Node JS without using Apache? Would it cause a problem if Node sits on port x and Apache on ports 80 and 443? Would they ever conflict?

2
  • Apache's process will block until node has responded. Two things - first, this is completely wrong for proxied connections because at the networking level Apache uses non-blocking I/O just like node.js. Second, even if this was Apache instead of Apache2 (ie. old Apache) it doesn't matter since Apache is multi-threaded. A blocked process (thread really) will simply make Apache spawn a new process (actually thread but on Linux they're the same thing anyway) to service new connections. Commented May 17, 2015 at 20:00
  • The better thing (as I read) is using apache ngynx (not standar apache rules) as it is faster and allows better multithreaded proxying, but I still did not read too much about it. if i run through a ngynx config I'll tell Commented May 17, 2015 at 22:53

1 Answer 1

2

Try this

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

Then restart apache. And try it :) hope it helps and to not missing anything

EDIT To your answer about if there is any problem with apache before node.js. -> Not for me. Apache and node.js run great together. At least for me.

Sign up to request clarification or add additional context in comments.

2 Comments

If you dont understand, please tell and I´ll clarify it. Get Luck!
Is it parallels plesk ? anyway, the rewrite conds, must be in your vhost definition... It´s the same but better if you do it from parallels plesk admin to prevent them being deleted after a parallels restart or config change

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.