Serving Meteor from subfolder


#1

How can I make Meteor serve from a folder instead of the domain?

i.e. I’m trying to serve Meteor from a subfolder of the domain. Something like:
abc.com : nginx + php-fpm
abc.com/xyz: Meteor app
abc.com/xyz/admin: another Meteor app

I’ve been looking into how to achieve this, and none of the resources and/or samples I could get my hands on even mentions running a Meteor app as a folder under a domain.

I got the nginx side working, with the config below (I’m giving the full config, in case I’m doing something wrong):

location ^~ /xyz/ {
	location ^~ /xyz/admin/ {
		location ~* \.(?:css|gif|jpe?g|ico|js|png|otf|svg|ttf|woff)$ {
			root /home/trying/xyz/admin-website/public;
			expires 1w;
			access_log off;
			add_header Pragma public;
			add_header Cache-Control "public";
		}
		proxy_pass http://localhost:8030;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Host $host;
		if ($uri != '/') {
			expires 30d;
		}
	}
	location ~* \.(?:css|gif|jpe?g|ico|js|png|otf|svg|ttf|woff)$ {
		root /home/trying/xyz/customer-website/public;
		expires 1w;
		access_log off;
		add_header Pragma public;
		add_header Cache-Control "public";
	}
	proxy_pass http://localhost:8031;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "upgrade";
	proxy_set_header Host $host;
	if ($uri != '/') {
		expires 30d;
	}
}

I’m seeing the nginx proxying the requests to Meteor:

2016/05/04 11:57:36 [error] 16418#0: *156 open() "/home/trying/xyz/packages/jparker_crypto-md5.js" failed (2: No such file or directory), client: 94.102.75.38, server: www.jupytur.com, request: "GET /packages/jparker_crypto-md5.js?hash=4b8c0bf83206d5e0f92aafe2820bb160e35f1627 HTTP/1.1", host: "www.jupytur.com", referrer: "https://www.jupytur.com/sociatips/"
2016/05/04 11:57:36 [error] 16418#0: *149 open() "/home/trying/xyz/packages/meteorhacks_ssr.js" failed (2: No such file or directory), client: 94.102.75.38, server: www.jupytur.com, request: "GET /packages/meteorhacks_ssr.js?hash=809d34fd56a22d08a4d4a531d3855419aa097095 HTTP/1.1", host: "www.jupytur.com", referrer: "https://www.jupytur.com/sociatips/"
2016/05/04 11:57:36 [error] 16418#0: *152 open() "/home/trying/xyz/packages/session.js" failed (2: No such file or directory), client: 94.102.75.38, server: www.jupytur.com, request: "GET /packages/session.js?hash=9ac45190b217c0c6a6293b0769e5a83f9dc8c003 HTTP/1.1", host: "www.jupytur.com", referrer: "https://www.jupytur.com/sociatips/"

Simply put, I can’t figure out how to have Meteor serve from abc.com/xyz/ instead of abc.com. How do I achieve this?


#2

Look, i’ve struggled a bunch of days on how to achieve a similar situation, basically i wanted a Ghost blog as sub folder(app.com/blog) and i’ve resolved using proxy_pass.See my configuration:

server {

    listen 443 ssl;

    server_name example.com

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;


    location ~* "^/[a-z0-9]{40}\.(css|js)$" {
            root /opt/example.com/app/programs/web.browser;
            access_log off;
            expires max;
    }

    location / { #Meteor app
             proxy_pass http://127.0.0.1:3000;
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection 'upgrade';
             proxy_set_header X-Forwarded-For $remote_addr;
             add_header Cache-Control no-cache;

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

     location /blog { #Ghost app
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass http://127.0.0.1:2368;
    }

 .....

}

Try to proxy_pass the Meteor app only to “location /xyz”, then another location for the admin panel “location /xyz/admin”, and as the main “location /” put your main app in PHP.
This worked for me :slight_smile:


#3

That’s what I did. But Meteor does not care about the /xyz part and tries to serve its files from /. That is the problem I’m trying to solve.

So, you see, your situation is the opposite of mine.

You have / as Meteor, and /blog as Ghost.

I have / as non-Meteor, /xyz as Meteor. And I proxy_pass /xyz requests to Meteor, but Meteor does not care about the /xyz part and just tries to serve everything from /.


#4

Now i see your problem! Let me know if you resolve this,it’s a interesting situation :slight_smile:


#5

@necmettin I’ve managed to do it by using this in nginx config

location / {
    if ($arg_meteor_css_resource = "true") {
        rewrite ^ /search/$uri last;
    }
    if ($arg_meteor_js_resource = "true") {
        rewrite ^ /search/$uri last;
    }

    location /sockjs {
        rewrite ^ /search/$uri last;
    }
}