Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs domain without port number

Tags:

url

node.js

port

I have deployed my nodejs app on a VPS(ubuntu 10.04). I have hosted it on a subdomain (subdomain.myapp.com:3000) and I just have one IP address

By default port 80 is been used by apache as default. I just want that my app should run on port 3000 but URL should be (subdomain.myapp.com)

Is this possible in nodejs or do I have to tweak my virtual host or apache's files.

like image 602
Niraj Chauhan Avatar asked Jan 13 '13 12:01

Niraj Chauhan


People also ask

How do I run NodeJS without a port?

You can use the default port however. When users give browsers URLs without ports, they automatically apply the default port. For URLs like http://example.com/ or http://10.11.12.13/ the default port is 80. For https://example.com it's 443, and you need to use the https server class.

Why does node use port 3000?

3000 is a somewhat arbitrary port number chosen because it allows you to experiment with express without root access (elevated privilege). Ports 80 and 443 are the default HTTP and HTTPS ports but they require elevated privilege in most environments.

Can I run NodeJS on port 80?

Linux Mastery - Complete Linux Course We know that most of the time we want our node applications to listen on port 80. While it is a widely used technique and many times we don't need anything else then just simply mentioning the port as 80 in our project configurations.

What is the NodeJS default port number?

The default port for HTTP is 80 – Generally, most web browsers listen to the default port.


2 Answers

Yes it is possible

In your apache virtual host file configure with the following

<VirtualHost *:80>
    ServerName subdomain.myapp.com

    ProxyRequests off

    <Proxy *>
            Order allow,deny
            Allow from all
    </Proxy>

    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
    ProxyPreserveHost on
</VirtualHost>

You should have

NameVirtualHost *:80

on top of your file and also Proxy module installed for apache ( I think it is a default configuration for ubuntu )

LoadModule proxy_module lib/httpd/modules/mod_proxy.so

it must be in your httpd.conf file

then you should restart apache and it must be fine!

like image 189
drinchev Avatar answered Oct 16 '22 10:10

drinchev


Just an update of @drinchev answer with Apache 2.4.*

Enable the proxy mode :

a2ensite proxy_http
a2ensite proxy

Then :

<VirtualHost *:80>
    ServerName subdomain.myapp.com

    ProxyRequests off

    <Proxy *>
            Require all granted
    </Proxy>

    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
    ProxyPreserveHost on
</VirtualHost>
like image 35
mpgn Avatar answered Oct 16 '22 11:10

mpgn