I am using the express framework for nodejs on a Dreamhost VPS and I want to run my server on port 80 but all of the answers I've seen require sudo/root access but on a Dreamhost VPS I am not given this permission. I can't edit any of the Apache files. The only thing I am able to do is create a .htaccess file. How can I achieve this?
You can try to run Node on a different port (greater than 1024, since those of 1023 or lower require root) and just proxy the requests through Apache by adding something like this to your .htaccess file:
RewriteEngine On
RewriteRule ^/(.*)$ http://127.0.0.1:8080/$1 [P,L]
(In this example Node would be running on port 8080).
For anyone who comes across this and has Dreamhost, the solution I came up with was creating a proxy. In the Dreamhost panel there is an option to create a proxy for a domain that you can then direct to go to any port for that domain and I simply made the proxy go to port 3000 and then my node server ran on port 3000.
#Frxstrem's answer also works but it failed to work when I shared a link and is kind of a hacky solution.
Related
I've got a locally running reactJS app that I'd like to run as a subdomain on a domain hosted on virtualmin, so that the app can be hosted locally but seen publicly.
ngrok.io allows you to serve a locally running reactjs application (or a lot of other things) through a publicly visible subdomain.
(My intention is to answer my own question, because when I searched, I ran into a lot of dead ends. I tried to use as many keywords as I used while searching out the answer.)
On Virtualmin, click on 'Create Virtual Server'
For the domain name, use "subdomain.x.com"
Enabled Features: Setup DNS Zone (if necessary), apache website enabled, and apache ssl website enabled.
Click on Server Configuration -> Edit Proxy Website
Set "Proxy enabled?" to "Yes". Proxy to url: http://localhost:12809/
Run your reactjs app on your localhost. We're assuming it is running on port 8301.
On your localhost, establish an ssh tunnel to your server; do:
ssh -N -T -R 12809:localhost:8301 user#x.com
reload "subdomain.x.com" and your locally running reactjs app will be seen publicly there.
If you need websockets enabled, make sure to add this to your apache configuration file at Services->Configure Website->Edit Directives.
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://localhost:12809%{REQUEST_URI} [P]
in the RewriteEngine On section
edit: this was an unnecessary step when i originally wrote this, but i'm leaving it here to show how you can route through yet another server if you want/need:
) Download 'caddy' to your virtualmin user home directory: https://caddyserver.com/download
) Then run a reverse proxy on caddy from the port that will connect to your localhost (9000, in this case) to the port that is served from subdomain.x.com:
`./caddy reverse-proxy --from :12809 --to 127.0.0.1:9000`
) in this case you'd run your ssh on your localhost like 9000:localhost:8301
I have a node app that is setup on SSH by running node osjs run --hostname=dc-619670cb94e6.vtxfactory.org --port=4100.
It starts at http://dc-619670cb94e6.vtxfactory.org:4100/ without problems, but instead I want to serve it through HTTPS https://dc-619670cb94e6.vtxfactory.org:4100/ , where I receive an error ERR_CONNECTION_CLOSED.
If I use the port I'm unable to reach it with https, but https://dc-619670cb94e6.vtxfactory.org/ is accessible.
How can I serve the port 4100 through htttps?
Thanks.
This is an implementation detail of OS.js. Their docs recommend setting up a reverse proxy for servers. Doing this will give you more control over SSL and ports, like you want
https://manual.os-js.org/installation/
I am hosting my site on an AWS ec2 instance. I want to run a Node.JS server on port 8080 (or something similar), and I want all users going to example.com, to be sent to example.com:8080. For some reason, rewriting example.com -> example.com:8080 doesn't work because AWS doesn't allow accessing example.com:someport.
How can I force all users towards example.com:8080 without using plain Redirect? (I may be completely wrong and just doing things improperly)
Try this
RewriteEngine On
RewriteCond %{SERVER_PORT} !^8080$
RewriteRule ^/(.*) http://www.example.com:8080/$1
Do you have to use raw EC2? That is probably unnecessarily low level. Can you instead use Up or ElasticBeanstalk? Either one should make this easier.
Also, why does it need to be on port 8080? My guess would be, because when you develop locally, you use that port (because one doesn't develop locally using port 80). Why not have an ENV var where you set const port = process.env.PORT || 80, then invoke node with PORT=8080 node server.js when developing locally.
Of course, node crashes. A lot. It's kind of its thing. So, you don't want to ever run the command node filename.js on an ec2 instance... you want to use forever or pm2. And, you really want a reverse proxy (Nginx) sending traffic to your node instance... which is why I say use Up or Beanstalk. But if you must do it yourself, this walkthrough covers the bases.
how setting up nodejs on sharing host?
nodejs and git installed on my host and I access to ssh , but when I want to run my application , apache handle those routes.
I read some article but those said fix with httpd.conf and I don't access to httpd.conf
If you have the proper permissions you can forward all the traffic from port 80 that apache handles to the port that your node app is running. You can find examples on google if you search for keywords like apache, vhosts and reverse proxy.
I have to put sails.js in port 80, but apache is already using it. How can I put both (sails.js and apache) on the same port 80? I need it because in my company all the ports are blocked except for PORT 80. (This is a realtime application with nodejs and socket.io (websockets) and in the other side a php application). Thanks a lot
You have to run Sails on any free port (1337, for example) and use Apache with mod_proxy. Make sure it's loaded in Apache config, then your virtual host will be something like this:
<VirtualHost *:80>
ServerName www.youserver.com
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
</VirtualHost>
See mod_proxy documentation for more details.
Put nginx in front of sailsjs, and dump apache, or make apache run on a different port.
DigitalOcean has a great tutorial on doing this with two nodejs apps.. You can find it here.
I also wrote a blog post about it here
I do this on my server so i can run ghost blog, and sailsjs on the same server. This is how i have it setup.
NGINX Proxies blog.gorelative.com -> localhost:2368
NGINX Proxies gorelative.com -> localhost:1337
Just adapt the tutorial to proxy one domain to localhost:1337 for sailsjs, and add in the other hosts to host them normally.. or proxy the others to apache2, which probably is a waste of resources and not ideal.
AFAIK: With a bit more work your hosts don't even need to be on the same server. nginx can proxy to another server, and also do load balancing tasks.