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


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


This is my configuration:

location ~ /chat/(.*) {
        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


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?

1 Answer 1


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

  • 1
    Well, I'll have to fix it by making the subdomain chat.example.com then...
    – Suppen
    Feb 16, 2015 at 9:45

You must log in to answer this question.

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