Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:53:04+00:00 2026-05-31T03:53:04+00:00

I’m running Nodejs and Apache alongside each other. node-http-proxy is listening on port 80

  • 0

I’m running Nodejs and Apache alongside each other.

node-http-proxy is listening on port 80 and then forwarding requests to either Apache(:9000) or to Express(:8000).

My virtual hosts on Apache look like:

<VirtualHost 127.0.0.1>
    DocumentRoot "/localhost/myVhost"
    ServerName myVhost
</VirtualHost>

My question is, what is the “correct” way to have vhost like functionality on the Express/Nodejs side? I would prefer to not have to place each Nodejs app on its own port as is suggested here:

https://github.com/nodejitsu/node-http-proxy
(Section titled “Proxy requests using a ‘Hostname Only’ ProxyTable”)

I noticed Connect (which as I understand it, gets bundled in Express) has some vhosts functionality. Should I be using that? If so, what would be the correct way to run it alongside node-http-proxy?

http://www.senchalabs.org/connect/middleware-vhost.html

I also noticed this other module called “Cluster”, it seems to be related but I’m not sure how:

http://learnboost.github.com/cluster/

While not wanting to overwhelm, I also came across one called, “Haibu” it seems to be related but I’m not sure if it would just be an all out replacement for using vhosts:

https://github.com/nodejitsu/haibu

Note: I’m a front-end guy, so I’m not very familiar with a lot of server terminology

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:53:05+00:00Added an answer on May 31, 2026 at 3:53 am

    I never figured out Haibu or Cluster. But I did find a good solution that addressed my issue. To my surprise, it was actually quite simple. However, I don’t know much about servers, so while this works, it may not be optimal.

    I set up virtual hosts like normal on Apache
    (http://httpd.apache.org/docs/2.0/vhosts/examples.html)

    I installed the following on Node

    • Express (http://expressjs.com/)
    • node-http-proxy (https://github.com/nodejitsu/node-http-proxy)

    Then, as a matter of personal style, I placed all my virtual hosts in a common directory (/localhost)

    I then switched Apache to listen on a port other than port 80. I just happened to choose port 9000 because I had seen that used somewhere. (In httpd.conf, changed “Listen 80” to “Listen 9000”). I also had to make sure that all my virtual hosts, as defined in extra/httpd-vhosts.conf were set to an IP based nameVirtualHost (127.0.0.1) instead of using a port (*:80).

    On the Node side, I created my app/server (aka node virtual host) that listened on port 8000 (somewhat arbitrarily choice of port number) See this link on creating a server with express: http://expressjs.com/guide.html

    In my /localhost directory I then created a file called “nodeHttpProxy.js”

    Using node-http-proxy, in nodeHttpProxy.js I then created a proxy server that listens on port 80. Using express, which wraps connect (http://www.senchalabs.org/connect/) I created my virtual hosts.

    The nodeHttpProxy.js file looks like this:

    // Module dependancies
    var httpProxy = require('/usr/local/lib/node_modules/http-proxy/lib/node-http-proxy')
    , express = require('/usr/local/lib/node_modules/express/lib/express');
    
    // Http proxy-server
    httpProxy.createServer(function (req, res, proxy) {
    
        // Array of node host names
        var nodeVhosts = [
            'vhost1'
            , 'vhost2'
        ]
        , host = req.header('host')
        , port = nodeVhosts.indexOf(host) > -1
            ? 8000
            : 9000;
    
        // Now proxy the request
        proxy.proxyRequest(req, res, {
            host: host
            , port: port
        });
    })
    .listen(80);
    
    // Vhosts server
    express.createServer()
    .use(express.vhost('vhost1', require('./vhost1/app')))
    .use(express.vhost('vhost2', require('./vhost2/app')))
    .app.listen(8000);
    

    As you can see, I will have to do two things each time I create a new Node virtual host:

    1. add the virtual host name to my “nodeVhosts” array
    2. define a new express virtual host using the .set method

    Of course, I will also have to create the actual host path/files in my /localhost directory.

    Once all this is done I just need to run nodeHttpProxy.js:

    node nodeHttpProxy.js
    

    You might get some weird “EACCESS” error, in which case, just run as sudo.

    It will listen on port 80, and if the host matches one of the names in the nodeVhosts array it will forward the request to that host on port 8000, otherwise it will forward the the request onto that host on port 9000.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I am writing an app with both english and french support. The app requests
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.