1

I have a situation that I think is a bit different from most. It's certainly different from any that I've encountered before:

I'm building a site for a client who wants/needs to retain full control over their canonical domain. Instead of simply pointing www.theirdomain.com and theirdomain.com to my server IP, they want to route traffic to them and let their Big-IP device send that traffic on to us at client.mydomain.com. I don't know Big-IP, but I suspect/assume this is a rewrite and the user will only see theirdomain.com.

In addition, the client has 2 subdomains whose landing pages will be served by my app and their IS team doesn't want anything to do with them. They're just updating DNS for those domains to point to my server. The landing pages, though, are served at client.mydomain.com/path/to/landing/page.

Since we don't want end users to ever see the client.mydomain.com, though, my normal process of doing a 301 redirect to the answering URL would seem to create some unnecessary traffic:

  1. My server answers the request to sub.theirdomain.com
  2. Instead of simply answering the request, my server redirects to www.theirdomain.com/path/to/landing/page
  3. Their Big-IP sends them right back to my server (the same one they just left), but with the correct domain.
  4. My server renders the content.

In step 2, instead of redirecting out to their device, can I simply rewrite the URL to www.theirdomain.com and serve the content directly? Better ideas also welcome. As I said, this isn't something I've encountered before and I'm looking for options.

2
  • Maybe your are looking for proxy pass ?
    – krisFR
    Sep 22, 2014 at 20:11
  • Not really (at least I don't think so). What I'd really like to do is server local content under a different domain without making that extra external request at all. Sep 22, 2014 at 20:16

1 Answer 1

0

We have several clients that have it set up so they retain control over their own DNS, as some of them only have subdomains that point at us. We are using nginx as a load balancer that also handles redirects, and we have our redirects in the default vhost file (00default). Nothing too complex, it works quite well for us:

if ($host ~* "^ourdomain.com$") {
  rewrite ^(.*)$ http://www.ourdomain.com$1 permanent;
}

if ($host ~* "^subdomain.otherdomain.com$") {
  rewrite ^(.*)$ https://ourdomain.com$1 permanent;
}

if ($uri !~* (/option/.*|/simple/.*|/embed/.*|/mini/.*|/someOtherOption\.action.*|/otherOption\.action.*|/file/[0-9a-zA-Z]+/html5.*|/file/[0-9a-zA-Z]+/html5mobile.*|/thumbnail/.*) ) {
  set $cname_match "N";
}

if ($host !~* "(.*\.)?ourdomain\.com|videos\.yetanotherdomain\.com") {
  set $cname_match "${cname_match}N";
}
if ($cname_match = "NN") { rewrite ^.*$ http://www.ourdomain.com/; }

if ($uri !~* (/thumbnail_.*|/vcomments/.*|/onethmb.gif$|/crossdomain.xml$|/otherthmb[0-9]+.gif$)) {
  set $thumb_redirect "Y";
}
    if ($host ~* "^(cdn-)?thumbs\.ourdomain\.com") {
      set $thumb_redirect "${thumb_redirect}Y";
    }
    if ($thumb_redirect = "YY") { rewrite ^.*$ http://www.ourdomain.com/ permanent; }

 location / {
   proxy_pass      http://ourdomain_apache_pool;
   error_page 404 @fallback404;
   error_page 403 @fallback403;
 }
 # redirects
 location /learn-more {
   rewrite /learn-more/? http://www.ourdomain.com/features permanent;
 }
 # help
 location ~* ^/help/zendesk/*.*$ {
   proxy_pass      http://ourdomain_ruby_pool;   
 }
 location ~* ^/help/*.* {
   rewrite ^/(.*) http://support.ourdomain.com permanent;
 }

It does seem to me that you could take one of the above rewrite rules, like:

if ($host ~* "^subdomain.otherdomain.com$") {
  rewrite ^(.*)$ https://ourdomain.com$1 permanent;
}

and just have them point the DNS to their domain at your server, then rewrite it as you pleased.

4
  • Your configuration is cluttered of really bad pratices. Useless ifs everywhere that you can refactor in location blocks, if tests against regexs that could be converted into static strings, rewrite used where return is more appropriate to avoid evaluating regex without capture groups, etc ... Surely working, but what a waste of CPU resources. Sep 23, 2014 at 20:17
  • Thanks for pointing that out, Xavier - can you point me in the right direction for resources to learn how to set this up better? Sep 24, 2014 at 12:00
  • 1
    Roger, you can start reading carefully nginx.org/en/docs/http/ngx_http_core_module.html#location, then check wiki.nginx.org/Pitfalls out for a good pointer on how to change your configuration for better performance/readability. Sep 24, 2014 at 12:09
  • 1
    Thanks very much Xavier - I'm still learning, obviously, and appreciate having the mistakes we've made pointed out. Sep 24, 2014 at 13:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .