2

On my domain, I have a subdomain for Meteor applications, say

http://meteor.example.com/

Under this, I would like to put individual applicaions, with an URI for each. Say the meteor application Chat should have this URL:

http://meteor.example.com/chat/

This is my configuration:

location ~ /chat/(.*) {
        proxy_pass http://127.0.0.1:4000/$1;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;

        if ($uri != /snake_meteor/) {
                expires 30d;
        }
}

I followed this guide to config it.

Now, this partially works. It does pass the request on to the application, and it returns correct HTML for the page, but then the problems start. The returned HTML references resource files, like JS, CSS and images. The references in the HTML is unfortunately on the form

<script src="/somescript.js"></script>

so it requests

http://meteor.example.com/somescript.js

Absolute paths...

To change them in the application is not really an option. It's also not an option to put the resources on the root of the domain.

Is there anything I can do in the NginX config to get this working? Or do I have do this some other way, like another level of subdomains?


Edit: A friend of mine suggested checking the referer header. It partially works. Some of the files are fetched, but establishing a websocket and some other things fail.

My added config for this is

location / {
        if ($http_referer ~ /chat/) {
                rewrite ^(.*) /chat/$1 permanent;
        }
}

Is this an acceptable way of doing it? I'm sure this part of the config can somehow be rewritten to also take into account other meteor applications on the same domain, but I'm no expert at NginX config. A little help, please?

Suppen
  • 153
  • 1
  • 7

1 Answers1

3

Unfortunately the only reasonable solution is to fix the application so that it generates correct URLs. All other solutions will cause subtle issues.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58