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.
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.
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.
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.
The default port for HTTP is 80 – Generally, most web browsers listen to the default port.
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!
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With