1

I want to go to www.example.com and be redirected to subdomain.example.com/homepage without the url changing from www.example.com.

The catch being than my css and js is hosted at subdomain.example.com. I'm struggling with the last part. So far I have this:

http {
    upstream meteor_server {
        ip_hash;
        server 192.168.0.24:88;
    }
    server {
        server_name www.example.com;
        location / {
            proxy_pass http://meteor_server/homepage/;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    server {
        server_name subdomain.example.com;
        location / {
            proxy_pass http://meteor_server/;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
}

This allows me to access the subdomain just when i go to www.example.com I get 404s on each of the css and js files it attempts to download. I know there are better ways to do something like this but this appears to be the cleanest in our use case. Although I'm open to any ideas, a solution using nginx is favourable.

1 Answer 1

0

An Nginx fix would have been nice but I'm not sure if it was particularly appropriate use of nginx. I couldn't figure it out, so for anyone stumbling on it heres how I solved it in meteor with Iron-Router.

Meteor.startup(function () {
  if (Meteor.isClient) {
  var hostnameArray = document.location.hostname.split(".");
    if (hostnameArray[0] === "www") {
      Router.route("home", {template: "www-homepage"});
    }
    else {
      Router.route("home", {template: "subdomain-homepage"});
    }
  }
}

Hope this is useful to someone else. Credit to kevinpeter from this GitHub issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.