Note that there are some explanatory texts on larger screens.

plurals
  1. POnginx rewrites paths proxied to node.js
    text
    copied!<p>I'm trying to make a nodejs website/server download another website when the user goes to a URL looking like this: <code>http://example.com/test/http://google.com</code></p> <p>The problem is that nginx is rewriting the req.url to <code>/test/http:/google.com</code> when it should be <code>/test/http://google.com</code></p> <p><strong>app.js:</strong></p> <pre><code>var express = require('express'); var http = require('http'); var app = express(); app.configure(function(){ app.set('port', 8080); app.set('views', __dirname + '/app/server/views'); app.set('view engine', 'jade'); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.cookieParser()); app.use(express.session({ secret: 'super-duper-secret-secret' })); app.use(express.methodOverride()); app.use(require('stylus').middleware({ src: __dirname + '/app/public' })); app.use(express.static(__dirname + '/app/public')); app.enable('trust proxy') }); app.configure('development', function(){ app.use(express.errorHandler()); }); require('./app/server/router')(app); http.createServer(app).listen(app.get('port'), 'localhost', function(){ console.log("Express server listening on port " + app.get('port')); }) </code></pre> <p><strong>router.js:</strong></p> <pre><code>app.get('/test/*', function(req, res) { console.log("REQ.URL:"); console.log(req.url); res.send('200', req.url); }); </code></pre> <p>example.com file in <code>/etc/nginx/sites-enabled</code></p> <pre><code>server { server_name example.com; access_log /var/log/nginx/example.com.log; # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options location / { 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://127.0.0.1:8080; proxy_redirect off; } } </code></pre> <p>Is there a way to make nginx not rewrite like it does?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload