How to enable custom domains for my users?

I want my users to be able to use their own domain name to access my web service.

For example, if I have a user with a profile in example.com/users/david, how can I allow david to use exampledavid.com to access his profile page.

I do not want users to see example.com in the address bar, but instead, for david, you could view exampledavid.com.

+5
source share
2 answers

Your problem can be solved by rewriting the URL and manipulating the HTTP header or reverse proxy.

  • For Apache http server: use the ProxyPassReverse directive.

The ProxyPassReverse directive allows Apache to configure the URL in the Header header in HTTP redirect responses. For example, this is important when Apache is used as a reverse proxy to avoid bypassing the reverse proxy due to HTTP redirection on server servers that remain behind the reverse proxy.

Assume that the local server has the address http://wibble.org/ ; then

ProxyPass / mirror / foo / http://foo.com/
ProxyPassReverse / mirror / foo / http://foo.com/

Not only will it invoke a local request for http://wibble.org/mirror/foo/bar to internally convert it to a proxy request http://foo.com/bar (ProxyPass functionality here). He also takes care of redirecting the server foo.com sends: when http://foo.com/bar redirects it to http://foo.com/quux Apache configures it to http://wibble.org/mirror/foo/quux before forwarding the HTTP redirect response to the client.

  • For MS (R) IIS, use the Overwrite module:

Easily replace web application URLs for user-friendly results for search engines. URL Rewrite allows web administrators to easily replace URLs> generated by a web application in an HTML response with a more convenient and search engine friendly equivalent. Links can be changed in the HTML markup generated by the web application behind the reverse proxy. URL Rewrite makes it easy to process the contents of an outbound response and rewrite headers with outbound rewrite rules that work with HTTP request and response headers and with IIS server variables.

Additionally, you must ensure that exampledavid (dot) com is configured with a DNS provider to forward all requests to example.com.

Example DNS record:

NAME TYPE VALUE -------------------------------------------------- exampleXYZ.com. CNAME example.com. example.com. A 192.0.2.23 

Ref:

0
source

You can easily enable this by telling your customers to configure CNAME to point to your domain.

So, if your server is located at www.example.com, you report "david" to configure www.exampledavid.com to have a CNAME record pointing to www.example.com

On the server side, you will have a configuration that detects the domain that was requested and redirected and served the appropriate content in "david"

If your clients want to use the bare domain ie exampledavid.com on their servers, you will need to provide them with an IP address, however before that you will need to make sure that your IP address will not be changed and probably have a contract with who supplies it to provide this.

+1
source

Source: https://habr.com/ru/post/1241848/


All Articles