Reverse proxy passthrough for multiple websites - node.js

I'm building a website where there will be user generated content, for example under the url website.com. Each user might have a page (of their own content) somewhere like website.com/user/jack, website.com/user/lucy, etc. This number of users (as well as their names) are dynamic and can be added any time. I already have website.com working and deployed.
I'd like to be able for users who have their own domain name, e.g. jacks-website.com, to be able to use that domain name but effectively have it act and behave as website.com/user/jack. By this, I mean the following:
jacks-website.com is has the same DNS records as website.com.
jacks-website.com serves exactly the same content as website.com/user/jack. This also goes for any/all (nested) subpaths, i.e. jacks-website.com/custom-path -> website.com/user/jack/custom-path.
A user browsing jacks-website.com will have NOT be directed to website.com/user/jack. To them it should feel like browsing jacks-website.com directly.
I've tried playing around with Node's http-proxy package, where I would check what req.headers.host is then map it to a corresponding /user/jack path. However, I still couldn't get it to work as it would cause jacks-website.com to redirect to jacks-website.com/user/jack.
Also note that I'm fully using SSG/SSR on my website.com app, so no need to worry about client-site routing or anything.
Thanks a lot.

Related

Multiple domains and web app in Business Catalyst

I have set up a secondary domain on my BC hosting successfully and have already set it up to point to a homepage and the url stays the way I wish, for example www.[secondary domain].com
I now want to setup a web app to use my secondary domain rather than my default, does anyone know how I would achieve this?
Fore example at present it looks like this www.[default domain].com/[webapp name]/ I would really want it to read www.[secondary domain].com/[webapp name]
I am going to have to use redirects when promoting the page and just accept that the proper url is going to be www.[default domain].com/[webapp name]/
BC serves all content the same, no matter which domain it is accessed from.
Proper server-side 301 redirects are unavailable, since BC gives us no method to discriminate by domain. You can perform a client-side 'redirect' though, after comparing the hostname in Javascript (with something like document.location.host).
There is also Liquid Markup, which you can use to detect the domain and vary the served content accordingly.
You'll need to ensure all links to the app are fully qualified, including the preferred domain.
I'd also add canonical links (<link rel="canonical" href="...">) to each page of the app. This will indicate the preferred domain to search engines.
Note the inverse is also a problem; content on your primary domain will also be accessible through the secondary domain, causing rank dilution / duplicate content issues.

Put a subfolder onto a different server with CNAME

Here's the situation. Website.com is an ASP site which needs a blog that is to be Wordpress. So the website.com/blog needs to be hosted onto a php-friendly server. The company hosting the ASP site doesn't want to have anything to do with Wordpress so we have to use some of the shared hosting providers.
How do I have the Blog section placed onto an entirely different server? I've heard this is done with CNAME, but I've never used it. Most of the research I've done revolves around subdomains, but I need a subfolder mapping, and there's not much to read about putting subfolders onto different servers with a different IP and everything.
Thanks.
There are a few different options:
you can bring the traffic to your own server and then redirect to
the correct location
you can bring the traffic to your own server and then proxy it to the correct location
you can direct the traffic to the correct location either via full page or an IFRAME type mechanism
Each option has some benefits and drawbacks depending your devs knowledge level and your infrastructure. Regarding subdomains, you could use a combination approach where you, for example, use subdomain.yourdomain.com to point to a server instance (can be the same server or a totally different one) that maps the subdomain.yourdomain.com name to a specific path, usually via Host header.
A CNAME is a function in DNS that says "Whatever thing you wanted to find for this name, use the same thing for that other name instead". When you're working with web stuff the "thing" in there is nearly always an IP address.
That is, what a CNAME can do for you is to say that when a user's web browser tries to look up the IP address for website.com, it will use the IP address for someotherwebsite.com. Note the total absence of anything web-related, like subfolders, in this. CNAMEs work on whole domain names, nothing else. Since you want to serve only a part of the stuff at a particular name from another server, CNAME cannot help you. CNAME is the wrong tool for you problem. Do not taunt happy fun CNAME.
In order to serve website.com/blog from another server than website.com, you pretty much have to do some sort of reverse proxying (where the ASP site's server relays requests between the user and the Wordpress server). It's probably easier and more robust to give the Wordpress site its own name (blog.website.com or something), and redirect to that from website.com/blog, but only you can know if that's politically possible in your case.

Website A 'redirect' to subdomain of website B, with content of website A

There has been a question made towards me recently to do the following:
We have a website with Drupal running in IIS.
On that site is an URL Redirect to a website hosted externally, obviously with a name completely irrelevant to the name of our company.
The question now is the following;
They want to change to URL to a subdomain of our website. Example: from "www.external-site.com" to "www.sub.internal.com" (while still showing content of the external website)
They want the current page of that website to be reflected in the URL bar. So it wouldn't say "www.sub.internal.com", but it would say "www.sub.internal.com/solutions/page1.html" (instead of "www.external-site.com/solutions/page1.html")
It's possible that I forgot another 'condition' but have mentioned before this.
So, if someone visits through our URL Redirect to External-website, it needs to show our subdomain instead of their domain in the URL, AND it needs to show the current page when people start browsing while still using our subdomain in the URL.
Now, I checked the external-website, and it seems that most of the links available are relative links (if this would be any useful information).
Currently, the external website is hosted externally, and will remain to be so for next few years. (I believe we bought the company)
I have been asking around and looking up, and the best possible thing seems to use domain forwarding, but even then it still doesn't seem to comply with the entirety that they asked of me.
I am but a 'simple' .NET programmer, held responsible to do support for anything involving the websites, and I can't say I have extended knowledge about infrastructure. (But I can ask people to do this for me)
Is there anything that could solve this?
Thanks so much!
IIS's URL rewite and Application Request Routing (ARR) combo can help you what you want to achive. Here are few links which may guide you to configure ARR. Please note that these links dont exibit exact solution to your problem however you can take clue from it and fabricate your solution accordingly.
http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing
http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-rule-template
It sounds like you'll want to use a full-page iframe: do not redirect but show a page with an "inner page" instead: that inner page is the external web site. That way, users do not see the external site in their URL bar.
http://webdesign.about.com/od/iframes/a/aaiframe.htm
You need to configure the equivalent of Apache Virtual Host with Reverse Proxy on IIS.
See this answers:
https://serverfault.com/a/271030
and
https://stackoverflow.com/a/10003306/2131693

How to prefix all requests with ~username?

I'm testing moving my site to a new Linux server using cPanel which requires you to put in your IP and username (e.g. http://123.xxx.xxx.xxx/~username/). The problem is, all my image/JS/CSS links use paths like /css/style.css or /images/picture.jpg so none of the styles, scripts or images show up properly.
How do I set up a RewriteRule to prefix ~username to all requests?
Before moving site, if it was working with only domain name and with redirection then now it should also work with server IP and username, Make sure the permissions and ownership of /css/style.css or /images/picture.jpg are correct.
Also check it once adding exact path manually like 'http://123.xxx.xxx.xxx/~username/css/style.css'.
I was able to get around the issue by setting the domain to a dedicated IP instead of shared, so I could access the site using 123.xxx.xxx.xxx instead of 123.xxx.xxx.xxx/~username.

Preferred way to direct user's domain names to my web app?

Background context: ASP.NET / IIS (not sure if it matters)
I have a web app at example.com, and a user of my app gets his own content page at an address like example.com/abc-trinkets. I would like to offer the user the ability to point his own registered domain at my web app so his content is accessed at abctrinkets.com. Initially looking on the order of 10-100 users with custom domains.
Ideally, I would like my user to just have a single hostname or IP address that he needs to know to configure properly with his registrar, and if I change the setup of my servers (different host, change addresses, load balancing, etc.) the user will not have to change his settings.
I have no trouble handling the requests once they hit my web app, but I am looking for input on the best way to set the routing up so requests actually come to my app/server. I would like a "catch-all" type of behavior that does not require me to individually configure anything for each domain a user might point to me.
I assume I will need some kind of layer between the address I give my user and my actual server ... is this like a managed DNS service or some other type of nameserver thing I would set up with my host? Is this something simple that should already be handled by a few simple settings on my webserver? I worry that I am making this more complicated than it needs to be.
Write a script that examines the Host header in the request. In your example, if it's abctrinkets.com, then you'd either redirect or forward the request to /abc-trinkets. You'd still need a database or something for mapping the domain names to the URLs; if you're going to allow arbitrary domain names for each user account, then there's no possible way to avoid that.

Resources