Reverse proxy under location other than /


#1

Hello.

Right now, I host my mineos under a reverse proxy. It works great, but I have it under the root location of a subdomain. So something like minecraft.server.domain.com/. I’d like to host it under a different location, like minecraft.server.domain.com/mineos/, so that I can put a friendly landing page under /.

My issue is that the API requests and script loads in mineos are hard coded with paths. Putting mineos under /mineos/ causes all the scripts not to load and such because they’re trying to load from /.

With this nginx.conf,

server {
  listen 80;
	listen 443 ssl;

	root /config/www;
	index index.html index.htm index.php;

	server_name minecraft.*;

	location / { #shows landing page
		try_files $uri $uri/ /index.html /index.php?$args =404;
	}
	location /mineos/ { #proxy to mineos
		include /config/nginx/proxy.conf; #redirects to https and some other stuff, not really relevant here
		proxy_pass https://10.10.11.250:8448/admin/;
	}
        location /map/ { #proxy to dynmap
		include /config/nginx/proxy.conf;
		proxy_pass https://10.10.11.250:8123/;	
   }
}

I get the following errors.

They’re making requests to / when they need to be making requests to /mineos/. Any ideas on a fix? Can I self-host index.html?


#2

The issue you’re likely running into is the relationship of those npm directories after you add the reverse proxy:

I haven’t had a chance to test this, but here, from line 230 to 237, it’s saying how the webserver will respond to /moment, and other directories so long as they match that URL.

In light of your reverse proxy pre-pending /mineos/, I’d assume you’d simply also need to prepend /mineos to these 8 lines. More likely it’ll be cleaner to just add a new variable in NodeJS and then add that before all the paths, e.g.,:

app.use('/admin', express.static(__dirname + '/html'));

TO
var url_prefix = “/mineos”;
app.use(url_prefix + ‘/admin’, express.static(__dirname + ‘/html’));

Gonna take a stab and also assume that for full functionality, you’ll want to do this for all the paths starting at line 178 up till 230. (the app.use, app.get, app.post ones, but not res.sendFile)