question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proxied host port is stripped from HTTP_HOST

See original GitHub issue

When I use version 2.7.6 PHP’s $_SERVER[‘HTTP_HOST’] returns localhost:3000 but on the latest version, 2.7.12, it returns just localhost, without the port number. This is breaking my sites.

Example config:

gulp.task('serve', ['stylesDev'], function () {
  browserSync.init({
    notify: false,
    proxy: 'localhost/src/'
  });
  gulp.watch(['src/**/*.php'], reload);
  gulp.watch(['src/styles/**/*.{scss,css}'], ['stylesDev', reload]);
  gulp.watch(['src/scripts/**/*.js'], reload);
  gulp.watch(['src/images/**/*'], reload);
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
KevinRaycommented, Jun 26, 2015

I’m referring to the value returned by the PHP $_SERVER variable when using browser-sync’s proxy: //in gulpfile.js browserSync.init({ proxy: ‘localhost/’ });

Here’s an example:

//Without browser-sync

<?php echo $_SERVER['HTTP_HOST'];?>

//returns localhost

//With Browser-Sync v2.6.5

<?php echo $_SERVER['HTTP_HOST'];?>

//returns localhost:3000

//With Browser-Sync v2.7.12

<?php echo $_SERVER['HTTP_HOST'];?>

//returns localhost

The issue I have is that, with the latest browser-sync version, it loads the site to http://localhost:3000/ on startup but the links in the site, which are generated dynamically by using $_SERVER[‘HTTP_HOST’] are using http://localhost/. The difference, not appending the :3000, raises browser errors related to cross-origin requests for resources.

0reactions
elimccommented, Jul 29, 2015

Possible related issue when I try to save a WP post:

XMLHttpRequest cannot load http://127.0.0.1/jump_start/wp-admin/admin-ajax.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

Here’s the relevant gulpfile.js code:

        browserSync.init({
            proxy: 127.0.0.1/jump_start/,
            tunnel: "tunnel"  // Set the SSH tunnel for mobile testing.
        });

However, this is only an issue on an older site. I created a brand new site and had no issues. When I create a WP site, I install it at 127.0.0.1/mydir/. I run Gulp and it loads as localhost:3000/mydir/ just fine. Not sure if that helps @KevinRay.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Port number is stripped from Host http header. #1347 - GitHub
When a http request hits kong with a http header Host: en.wikipedia.org:8080 then Kong correctly forwards this http header, but it strips ...
Read more >
What causes HttpHostConnectException? - Stack Overflow
A "connection refused" error happens when you attempt to open a TCP connection to an IP address / port where there is nothing...
Read more >
http redirect and port stripping - DevCentral
All,. Can anyone assist me with an iRule that would strip a certain string out of a url? The customer has a vip...
Read more >
http-host - ADMX Help
Description: Host name to use for HTTP requests. Type: String. Default: ''. Supported on: Host name for HTTP requests. Registry Hive ...
Read more >
Using Behind a Reverse Proxy — waitress 2.1.2 documentation
If you're using Waitress behind a reverse proxy, you'll almost always want your reverse proxy to pass along the Host header sent by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found