简体   繁体   中英

Is it possible to use the same node.js server for two/three different domains (aliases)?

Is it possible to use the same nodeJS server for two/three different domains (aliases)? (I don't want to redirect my users. I want them to see the exact URL they typed in the address bar. However, all three domains are exactly the same!)

I want my users to be logged in on all three domains at the same time, in order to avoid any confusion.

What is the simplest way to do this and avoid cross-domain issues?

Thanks!

If you mean that all domains will serve the same nodejs app then Yes you can do that.

but if each domain should open a different application then you must have a reverse proxy running on the server to handle and manage the sites/vhosts.

You may install nginx and use it as reverse proxy server or look for http-proxy a library for nodejs.

If you would like to manage the vhosts in your app you can look for vhost middleware for nodejs and use it

Choose one of:

Use some other server (like nginx) as a reverse proxy.

Use node-http-proxy as a reverse proxy.

Use the vhost middleware if each domain can be served from the same Connect/Express codebase and node.js instance.

This is a very broad question. Moreover, it is generally a pretty bad idea, SEO-wise, to have multiple independent domains that each serve the same content.

Logging in is generally either done through Cookies, or through extra parameters in the URL. Cookies are always domain-specific, for obvious security reasons. If you want to ensure folks will be logged in to all the domains at once, you can create an internal purpose-driven domain to handle authentication (without such domain showing in URL bar, and only being used for HTTP redirects, effectively); such domain will store the login state for all the rest, and the rest would pick up the login state through such purpose-driven domain (through HTTP redirects).

In general, however, this sounds like too much trouble. Consider that, perhaps, some users specifically want to use different domains for different accounts, so, you'll effectively break their usage if you mandate that a single login be used for all of them. And, back to the original point, doing this is pretty bad for SEO, so, just don't do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM