Stefan Stefan - 3 months ago 6x
Javascript Question

Running behind nginx at a sublocation

I am trying to run an Application on a raspberry my at my home.

Express and are running on port 3001. Accessing the Application at http://[IP]:3001 works fine. I would like to access the application at http://[IP]/ttt.

I configured nginx like this:

location /ttt/ {
proxy_pass http://localhost:3001/;

On the server i run these lines of code:

var express = require('express');
var app = express();
var http = require('http').Server(app);


app.use(express.static(__dirname + '/public'));
app.use('/node_modules', express.static(__dirname + '/node_modules'));


var io = require('')(http, {path: '/ttt/'});


http.listen(3001, function () {
console.log('Listening on port 3001');

and at the client I include like this:

<script src=""></script>

and connect like this:

socket: Socket = io.connect({path: "/ttt/"});

The problem:

I get all resources (html, css, js incl., but in the browserlog i get error messages, that it was not able to get http://[IP]/ where t changes frequently.

It reports status 404, it's obvious, because nginx doesn't respond at /

Thanks in advance!


If I understand your proxy configuration correctly, it is going to strip off the /ttt from the path before forwarding on to port 3001. As such, your initialization is not correct on the server.

Change this:

var io = require('')(http, {path: '/ttt/'});

to this:

var io = require('')(http);


And, make sure that your client file that's loading into the browser is actually the latest edited client file. You can check it with View/Source in the browser to see exactly what file you're running.