I own a server running whm / cpanel, and I have recently been experimenting with node.js. I have a little node test server running and i would like to point a domain at it. Up till now, I have been using whm to create accounts and deal with domains, but this is a different scenario, and I have little knowledge about how to make a domain point to something on my server when there are multiple other domains pointing to other different things on my server at the same time.
Thanks
Ok, I have never tried this, but you could use a rewrite rule in a .htaccess file and rewrite everything to goto to port 8000 where you have your node.js server running.
So first, set up your node.js server to listen to port 8000.
Then, create your domain like normal in cpanel, and in the doc root add a .htaccess file with this rewrite:
RewriteRule ^ "\ http: \ / \ / 127.0.0.1 \:% (8000) REQUEST_URI" [P, QSA, L]
That should just forward everything internally to port 8000 where node.js will take care of it. But I don't know how persistent connections / websockets will work with this strategy. It may be better to skip apache in those cases by going directly to the port 8000 on your server.
Source: http://es.w3support.net/index.php?db=sf&id=59994
This is a little bit tricky, since cpanel is going to use apache to configure the domains, and apache has already taken port 80 without a doubt, so you can't share port 80 between apache and node.js. You will not be able to configure this through cpanel.
You could just point the domain to your server and have node listen to another port such as 8000.
Then go to http://mydomain.com:8000/
So apache/cpanel handles requests to ports 80 and 443, and node handles requests to port 8000.
It is very possible to run multiple web servers on one box, but they each need their own port(s)
I managed to do it like that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} !^3000$
RewriteRule ^ http://%{HTTP_HOST}:3000%{REQUEST_URI} [P,QSA,L]
</IfModule>
Anything else didn't worked for me :(
Here I check if the port is not 3000 and if the protocol is not https then I point the domain to port 3000 (you can put the port you use with node.js) you can remove the RewriteCond %{HTTPS} !=on in case you don't care to check for the protocol.
I do some R&D locally but in production I believe I will use nginx + node instead of apache.
Related
I'm trying to set up a redirect from http://domain.com:443 to https://domain.com.
Now http://domain.com:443 redirects me on https://400.shtml with code
301, moved permanently
https://domain.com:443 to https://domain.com works fine.
This strings in .htaccess doesn't help:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
I'm trying to set up a redirect from http://domain.com:443 to https://domain.com.
This makes no sense whatsoever!
You cannot listen to http and https on the same port. 443 is the standard port for https. Webservers that listen to port 443 will expect the first message it receives to be a request to set up the https session and not a http message.
Even if you decided to go against all sane advice and set up your webserver to NOT use https on port 443, so you could respond to the http://domain.com:443 request then the redirect will work but then https://domain.com will not work as this will try to use port 443 (default port for https) which you've now stopped using https - so this still won't work.
Use port 80 for http and port 443 for https like everyone else does. You can use different non-standard ports if you want (e.g. 8443) but don't mix these two standard ports up - it doesn't make sense, it's asking for trouble and it won't work.
I have an apache webserver listening on port 80. With apache, a PHP/MySQL system based on Zend framework. And I also have a node server listening on port 3000.
When a client sends a request, always on port 80, it's therefore first handled by apache. I would like to apply the following rules before treating the request:
if content-type is "application/json" then
use apache web server
else if content-type is "application/zend" then
use apache web server
else
use node server
Here content-type is sent in the request headers. Content-type "application/zend" is a custom content-type to say that, for this type of particular request, we don't want to use node server (I need this for some reasons).
I've tried to modify httpd-vhosts.conf with
ProxyPreserveHost on
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
But that's of course not enough as not everything should be handled by the node server (listening on port 3000). Hence some rules should be added. But I'm unsure where/how. I also tried to change the .htaccess file, but not sure how either.
Any help would be great! Thanks!
This should work (in .conf file):
RewriteEngine on
RewriteCond %{HTTP:Content-type} !=application/json
RewriteCond %{HTTP:Content-type} !=application/zend
RewriteRule ^ http://%{HTTP_HOST}:3000%{REQUEST_URI} [P]
Keep in mind that this might carry a performance penalty, and if most of your requests end on node, we should perhaps search for better solution.
I am using AWS to run my application based on MEAN stack. I am using load balancer with three instances of Node application servers and three instances of mongo database server on cluster. Following is my requirement.
1. Use load balancer to support only HTTPS
2. Node should run the HTTP server only
3. Load balancer will redirect HTTPS and HTTP both request to Apache which will redirect to Node
I tried AWS and created Load balancer. HTTPS only works when I keep both 80 (HTTP) and 443 (HTTPS) port redirection to 80 (HTTP) port of Apache node. Therefore as of now I kept both port redirection on load balancer.
Also, I have defined both 80 and 443 inbound traffic as security group.
How can I make sure that even if user type HTTP or HTTPS URL in the browser, my load balancer should always server HTTPS and user should only access HTTPS? Following is architecture diagram for reference.
Please advice.
At the load balancer, direct the port 80 listener to port 8080 on the instance.
In Apache, rewrite port 8080 to port 443.
E.g.:
<VirtualHost *:8080>
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
</VirtualHost>
The RewriteCond may be redundent...
iHello everyone,
I'm in trouble with mod_rewrite in apache2
i'm trying to redirect all traffic incoming on localhost/music to localhost:8080, i've read a lot on apache documentation but i could not find a working example (http://httpd.apache.org/docs/2.0/misc/rewriteguide.html)
Can anyone tell me how to do this?
And no, i'm not trying to redirect traffic to tomcat (so i imagine i can't use mod_jk), i just want to see on alias /music my other app running on port 8080, it's a web stream music player called CherryMusic that is written in python and runs with html5.
I'm on debian server (precisely running raspbian on a raspberry pi)
Thanks in advance
in the following example, if your request to /music/(example.mp3) it will redirected with http status 302 to http://localhost:8080/example.mp3
RewriteEngine On
RewriteRule ^/music/(.*) http://localhost:8080/$1 [L,R=302]
In the above example the browser will be redirected to http://localhost:8080/example.mp3 (will work only for you cause it redirected to localhost)
if you are looking to proxy the request - the web server will connect to localhost:8080 , than you can do:
RewriteEngine On
RewriteRule ^/music/(.*) http://localhost:8080/$1 [L,P]
Is it possible to redirect domain.com:88 to domain.com:8080 using htaccess & mod_rewrite?
And example please?
If htaccess can't do it, waht are other options?
If you get requests on different ports you need to have servers listening on those ports. Inside those servers you can certainly configure rewriting rules, you don't even have to check the port, since it is implicitly given inside the servers logic.
Note that you can configure several virtual servers inside an apache http server.
You can also configure a single server to listen on several ports. Check for documentation about the Listen configuration option inside the http server configuration. Then indeed you have to test for the port. You can do that inside the rewriting module by using the RewriteCond command together with the SERVER_PORT variable. So something like:
RewriteEngine on
RewriteCond ${SERVER_PORT} 88
RewriteRule ^(.*)$ http://some.server.addr:8080/$1 [QSA,L]