2

So I have a nodejs app running on port 8081:

http://mysite.com:8081/

I want to access it simply by going to http://mysite.com/ so I setup a virtual host with expressjs:

app.use(express.vhost('yugentext.com', app));

That seems too easy, and it doesn't work. Am I confused about how expressjs vhosts work?

alt
  • 13,357
  • 19
  • 80
  • 120

3 Answers3

3

if you want to do these via express well, the problem comes from your dns setup, not from the express code.

Add an A entry to your domain like these:

127.0.0.1 localhost *.mysite.com *.www.mysite.com

You should wait to the DNS propagation. (from seconds to hours).

If apache or other web server is running any vhost on port 80 there will be conflicts.

And the other way:

nodejs and express are far away from the performance offered by apache and nginx (vhost/proxy stuff).

Nginx>Apache (fits better with nodejs)

Creates a proxy from mysite.com to mysite.com:8080

On these way nodejs and express handles the ui, methods, httpserver etc, and Nginx or Apache the proxy , vhost, and managing your static assets sooo fast.

check these config here: Trouble with Nginx and Multiple Meteor/Nodejs Apps

Community
  • 1
  • 1
jmingov
  • 13,553
  • 2
  • 34
  • 37
  • I also run rails apps off this server on port 80, what's my best bet in terms of speed? – alt May 06 '13 at 10:15
  • 2
    Here you go: [USING NGINX TO AVOID NODE.JS LOAD](http://blog.argteam.com/coding/hardening-node-js-for-production-part-2-using-nginx-to-avoid-node-js-load/). So good article. – jmingov May 06 '13 at 10:20
1

I think you're doing app.listen(8081). You should be doing app.listen(80). I have no experience with express vhosts, but you don't need them for this simple use case.

Myrne Stol
  • 11,222
  • 4
  • 40
  • 48
0
upstream node-apps {
  server host_ip_1:3000;
  server host_ip_2:3000;
}

server {
    listen 80;

    server_name localhost;
        location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-NginX-Proxy true;
          proxy_pass http://node-apps/;
          proxy_redirect off;
        }
}

this is my nginx config, proxy pass multiple servers, good luck :p

ethan
  • 620
  • 1
  • 6
  • 25