Reverse proxy under location other than /

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?

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)

Hi,

I’m very interested into making the same thing. But I can’t achieve adding the subpath.
Here is my config:

    app.get('/mineos' + '/', function(req, res){
        res.redirect('/admin/index.html');
    });

    app.get('/mineos' + '/admin/index.html', ensureAuthenticated, function(req, res){
        res.sendFile('/html/index.html', response_options);
    });

    app.get('/mineos' + '/login', function(req, res){
        res.sendFile('/html/login.html');
    });

    app.post('/mineos' + '/auth', passport.authenticate('local-signin', {
        successRedirect: ('/admin/index.html'),
        failureRedirect: ('/admin/login.html')
        })
    );

  app.all('/mineos' + '/api/:server_name/:command', ensureAuthenticated, function(req, res) {
    var target_server = req.params.server_name;
    var user = req.user.username;
    var instance = be.servers[target_server];

    var args = req.body;
    args['command'] = req.params.command;

    if (instance)
      instance.direct_dispatch(user, args);
    else
      console.error('Ignoring request by "', user, '"; no server found named [', target_server, ']');

    res.end();
  });

  app.post('/mineos' + '/admin/command', ensureAuthenticated, function(req, res) {
    var target_server = req.body.server_name;
    var instance = be.servers[target_server];
    var user = req.user.username;
    
    if (instance)
      instance.direct_dispatch(user, req.body);
    else
      console.error('Ignoring request by "', user, '"; no server found named [', target_server, ']');
    
    res.end();
  });

  app.get('/mineos' + '/logout', function(req, res){
    req.logout();
    res.redirect('/admin/login.html');
  });

  app.use('/mineos' + '/socket.io', express.static(__dirname + '/node_modules/socket.io'));
  app.use('/mineos' + '/angular', express.static(__dirname + '/node_modules/angular'));
  app.use('/mineos' + '/angular-translate', express.static(__dirname + '/node_modules/angular-translate/dist'));
  app.use('/mineos' + '/moment', express.static(__dirname + '/node_modules/moment'));
  app.use('/mineos' + '/angular-moment', express.static(__dirname + '/node_modules/angular-moment'));
  app.use('/mineos' + '/angular-moment-duration-format', express.static(__dirname + '/node_modules/moment-duration-format/lib'));
  app.use('/mineos' + '/angular-sanitize', express.static(__dirname + '/node_modules/angular-sanitize'));
  app.use('/mineos' + '/admin', express.static(__dirname + '/html'));

This doesn’t work. I get Cannot GET /admin/index.html

Could you help me to set that up ? You said that we should edit app.use, app.get, app.post but not res.sendFile. But what about res.redirect and app.all ?

Thanks in advance for any answer, have a great day