Search code examples
nginxproxygulpmiddlewarebrowser-sync

Browser-Sync Proxy Middleware


I have a question regarding proxy middleware

I initialize Browser-Sync like this :

gulp.task('browser-sync', function() {
    files = [
        '**/*.php'
    ];
    browserSync.init(files,{
        open:false,
        port: 3000,
        ui: {
            port: 3000 + 1
        },
        proxy: {
            baseDir: "./",
            target : "http://example.com",
        }
    });
});

And I use nginx to proxy to http://127.0.0.1:3000

server {
    listen EXTERNAL_IP:80;
    server_name development.example.com;
    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}

However browser-sync calls 127.0.0.1:3000 instead of http://development.example.com How can I tell browser-sync that it should call http://development.example.com ? Thanks!


Solution

  • server {
        listen EXTERNAL_IP:80;
        server_name development.example.com;
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://127.0.0.1:3000;
        }
    }
    

    It was actually a nginx thing :)