Skip to content

Instantly share code, notes, and snippets.

@jerowe
Last active January 19, 2016 06:05
Show Gist options
  • Save jerowe/cc719dc611e4b8de8ae4 to your computer and use it in GitHub Desktop.
Save jerowe/cc719dc611e4b8de8ae4 to your computer and use it in GitHub Desktop.
Nginx and Express Config with Base Url

#Nginx

    #nginx.conf
    location /foo {
        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:3000/foo;
        proxy_redirect off;
    }

#Express

    #app.js
    var express = require('express');
    var app = express();

    app.use('/foo', express.static(__dirname + '/public'));
    app.set('trust proxy', true);

    var server = app.listen(3000, function () {
        var host = server.address().address;
        var port = server.address().port;

        console.log('Example app listening at http://%s:%s', host, port);
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment