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.

kasperd
  • 29,894
  • 16
  • 72
  • 122
jackkav
  • 111
  • 1

1 Answers1

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

jackkav
  • 111
  • 1