How do I enable custom domains for my users?

后端 未结 3 933
悲&欢浪女
悲&欢浪女 2021-02-19 19:00

I am looking to allow my users to use their own domain name to access my web service.

For example if I have a user with a profile at example.com/users/david how can I a

3条回答
  •  悲&欢浪女
    2021-02-19 19:28

    Your issue can be solved with URL rewrite and HTTP Header manipulation or reverse-proxy.

    • For apache http server: use ProxyPassReverse directive

    The directive ProxyPassReverse lets Apache adjust the URL in the Location header on HTTP redirect responses. For instance this is essential when Apache is used as a reverse proxy to avoid by-passing the reverse proxy because of HTTP redirects on the backend servers which stay behind the reverse proxy.

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

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

    will not only cause a local request for the http://wibble.org/mirror/foo/bar to be internally converted into a proxy request to http://foo.com/bar (the functionality ProxyPass provides here). It also takes care of redirects the server foo.com sends: when http://foo.com/bar is redirected by him to http://foo.com/quux Apache adjusts this to http://wibble.org/mirror/foo/quux before forwarding the HTTP redirect response to the client.

    • For MS(R) IIS use Re-Write Module:

    Easily replace Web application URLs to produce user and search engine >friendly results. URL Rewrite permits Web administrators to easily replace the URLs >generated by a Web application in the response HTML with a more user friendly and search engine friendly equivalent. Links can be modified in the HTML markup generated by a Web application behind a reverse proxy. URL Rewrite makes things easier for outbound response content and headers rewriting with outbound rewrite rules that work with HTTP request and response headers and with IIS server variables.

    Additionaly, you must make sure that exampledavid(dot)com is setup with DNS provider to pass all requests to example.com.

    DNS Record Sample:

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

    Ref:

    1. https://en.wikipedia.org/wiki/CNAME_record

    2. http://www.akadia.com/services/apache_redirect.html

    3. http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

    4. http://www.iis.net/downloads/microsoft/url-rewrite

提交回复
热议问题