How can i link two NodeJS servers under one domain? - node.js

for example i have a website that hosts a messenger app, it's written using Node JS on the back-end and has a server running on an obscure port (port 3455)
Currently my domain is being used to host my portfolio under a different port. the domain would be:
mydomain.com/
Is there anyway i could make it so that the app using port 3455 connects when i visit:
mydomain.com/messengerapp
even better would i be able to create a subdomain so its:
messenger.mydomain.com

You can achieve this by 301 redirection code. If you have apache server, add redirection rule to .htaccess and if you have nginx server, add redirection rule to its config file.

Related

Configure Subdomain with Heroku and Google domains?

I want to configure a subdomain on my main website. For example, www.something.com and something.com redirect to the same main website.
I want to add hi.something.com and for this, I used on my nodejs application vhost.
var vhost = require('vhost');
app.use(vhost('hi.something.com', require('./routes/hiIndex')));
//In (./routes/hiIndex) theres just an app.get telling it which page to render when it reaches this URL
When testing it locally, it works, but once I deploy my application to heroku and try to access hi.something.com it doesnt work, it redirect me to the main website, meaning something.com
Do I need to add some extra configuration, perhaps on the DNS settings for google domains or on Heroku?
If so, do I just point it to something.com ??
I have worked with redirect to other websites in form of subdomains but this is my first time trying to make it work from my own application.
You might have a subdomain catch-all redirect which prevents vhost in Node.js from picking up the subdomain. Try adding an A type record in your DNS settings that points to your Herokus server.

Redirect a request to a colud server from a godady server with .htaccess

Hi everyone need your support with the following problem. Please do apologies if I confuse you in anyways with my explanation.
I have a add-on domain (example.com) pointed to a Godaddy Linux server, domain is also in the Godaddy same account.
The web application for "example.com" is a Laravel 5.6 based one, and the web app has 'Get' type search form which needs to be forwarded to another Windows IIS server's port with all the query strings where another web app is hosted. the action of the from will be similar to below.
Request => http://sub1.example.com/route/method?var=val1&var2=val2&var3=val3
From this point on-wards the application has to continue work from the IIS server with the subdomain, which mean I am not expecting any replies from this IIS server to the Linux server.
Its been advised to use the subdomain to mask the forwarding to the IIS server, so I did like above with sub1 sub-domain. This subdomain has to be forwarded to a server's port as I mentioned above, something similar to below.
http://sub1.example.com => http://xxx.xxx.xxx.xx:9596
I did tried with the Godaddy's default subdomain forwarding with masking, but the query strings are not being forwarded and shows "Destination Unknown" error.
In a online forum its been advised not to go with Godaddy's forwarding instead go with .htaccess to have more control.
Therefore any possible solutions or your support with the redirection with .htaccess from web application to the external web server's specific port along with the query strings would be a life saver.
Thank you in advance.
As per the GoDaddy support, the domain forwarding to a IP's port is not possible with the Shared hosting.
The support suggested to go-ahead with the VPS and configure.
Please do comment, if this is wrong statement!

Wordpress and NodeJS on separate servers with htaccess

I've a 2 servers with the first my website on Wordpress and the second a dedicated server with NodeJS app.
Now on 1° server I've only access to .htaccess and I don't have permission to edit apache config. On this server I've an SSL cert and use it with Wordpress.
I need to have this:
When an use type https://www.example.com/app I want to redirect all requests to my second server nodejs.example.com:3000 without change the url and using same SSL cert.
Can I do that?
That's not possible without having admin access to the server. You'll need to install the apache proxy module apart from editing the configuration.
Ref: Run a NodeJS app with Apache

Redirect if hostname is incorrect with Node

We have a site hosted on IIS using http (port 80)
and we have a new site hosted on Node using https (port 443)
For reasons I won't go into too much, we can't use IISNode to run all websites on IIS.
This setup works unless someone uses https to reach one of the IIS hosted websites.
to reproduce:
http://nameprintgraphics.com -> IIS website
https://npgcloud.com -> Node website
if you type in https://nameprintgraphics.com however, you go to the node website. I want to prevent this behaviour. Since node is listening to port 443, is there a way to validate the hostname and if it's incorrect, redirect the user to http.
I know this is a bit of a convoluted way to fix things, but please work with me to find an interim solution to this problem. IISNode is preventing a legacy silverlight app from working in IIS for reasons I have yet to determine.
Why not check req.headers.host in your node app and if it matches, then simply send a redirect response immediately? For example:
// You may/may not want to append the `req.url` to the destination as well
res.writeHead(302, { Location: 'http://nameprintgraphics.com' });
res.end();

IIS Rewrite rule to rewrite to different web site

I have 2 web sites installed on the same IIS server. I need them both to listen on port 443 with HTTPS. I want them to use different application pools and be able to stop and start one without affecting the other. The clients of these websites are not able to configure the host header that they use in their HTTP requests.
Is there a solution? I have been trying to use IIS Rewrite rules. I have one website deployed on port 443 and the other on some unusual port. I tried setting up a URL rewrite on the first one that did a rewrite (not a redirect) to an absolute URL referencing the 2nd site on the unusual port. This always seems to produce an HTTP 404 response.
I can't do a redirect because the client gets redirected to the unusual port and the client is not allowed to make internet requests to non-standard ports.
I believe I am using IIS 6.2, that's what is says in the Help about in IIS MAnager
What options do I have?
It is not possible to rewrite to different applications in IIS, especially if they are in different application pools. Your only option is redirect if you want to do it simply using URL Rewrite.
Another alternative is to use ARR (Application Request Routing) and then proxy the call to the actual site depending on rules, this has also the advantage that sites could be in different machines or in the same one, and give you more flexibility. Obviously it does come with more complexity.

Resources