1

Ok I have a set up a working apache-virtual host configuration, which redirects the users on IP request. The setup is the following:

<VirtualHost *:80>  
DocumentRoot "C:\wamp\www\dns"
ServerName ConnectToServer

ProxyRequests off
<Proxy *>
        Order deny,allow
        Allow from all
</Proxy>
<Location />
        ProxyPass http://localhost:8080/
        ProxyPassReverse http://localhost:8080/
</Location>

The thing is that I want the apache server to redirect to the NodeJS server on request of a specific subdomain.

For example, apache will redirect to nodeJs server if the user requests www.stackoverflow.com but I want it to redirect to the server when a subdomain like www.stackoverflow.com/question is requested.

So, how to setup a Name-Based Virtual Host?

All I would like to know guys if this practice,making my server available through apache is good for production or should I find another solution like heroku or ngix? ?

1 Answer 1

2

There are a few ways to do this. I wouldn't recommend putting Apache in front of Node however. Nginx is better, but not really necessary anymore. What I do on my server is run a Node proxy in front of my Node apps and my Apache sites.

More details about how I implement this can be found in this answer: How to use vhosts alongside node-http-proxy?

Apache -> Node

<VirtualHost *:80>  
    ServerName www.question.com

    ProxyRequests off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    <Location /answer>
        ProxyPass http://localhost:3000/
        ProxyPassReverse http://localhost:3000/
    </Location>
</VirtualHost>
Sign up to request clarification or add additional context in comments.

13 Comments

Let me check it out.Is this solution a good practice ,production wise ?
OK Timothy first of all thanks for answering.Second, I like your setup I will defenetely try it in the near future. BUT, the thing with m setup is that I need ot upload my node.js server on a computer that runs wamp and I must not change settings etc in it because,simply, it does not belong to me. So, I want to have the minimum effect on the rest of the webserver that runs with wamp. How would I redirect froma subdomain to my nodejs server?
I think so, otherwise I wouldn't be using it in production! I haven't encountered any problems. The http proxy is simple enough that it just runs without issue. When you put Apache in front of node, it becomes a potential bottleneck for requests.
Updated my answer to include a VirtualHost setup which should work. You don't need the DocumentRoot since it's just acting as a proxy and not serving files.
Well,sorry maybe I didn't epxress the question as I should. As I say I have a similar setup like the one you answered. I want to take it from that stage and make it Name driven redirect. Where do we say in our code that when you type that domain (e.g. localhost:8080/question) you go to Node jsserver?
|

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.