Attualmente sto provando nginx e nodejs con connect che eseguono nodejs con proxy in nginx. Il problema che ho è che attualmente non eseguo nodejs sotto la radice (/), ma sotto/data come nginx dovrebbe gestire le richieste statiche normalmente. nodejs non dovrebbe sapere che è sotto/data ma sembra essere richiesto.Running nodejs in nginx
In altre parole. Voglio che nodejs "pensi" che funzioni a /. È possibile?
nginx config:
upstream app_node {
server 127.0.0.1:3000;
}
server {
...
location /data {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_node/data;
proxy_redirect off;
}
}
codice nodejs:
exports.routes = function(app) {
// I don't want "data" here. My nodejs app should be able to run under
// any folder
app.get('/data', function(req, res, params) {
res.writeHead(200, { 'Content-type': 'text/plain' });
res.end('app.get /data');
});
// I don't want "data" here either
app.get('/data/test', function(req, res, params) {
res.writeHead(200, { 'Content-type': 'text/plain' });
res.end('app.get /data/test');
});
};
Buona domanda. Non ho ancora trovato una soluzione per questo. Ho anche 2 percorsi nella mia applicazione;/app per l'app Web e/static per tutti i file statici. – andyuk
Fyi. Ho aggiunto un config.js e definito l'impostazione lì insieme a cose assortite. Almeno è in un posto come parte dell'app e non si sviluppa in start-up conf o difficile da trovare env vars. – Asken
Prova a inserire un '/' dopo il numero di porta. Questo ha funzionato per me. –