Nginx hide forwarded port number [closed]

2019-04-28 16:14发布

问题:

I'm trying to set up a simple static website, and I have an issue with nginx that's complicated by a number of things, most notably the fact that my ISP blocks all inbound port 80 traffic.

First, I got a web forward set up so that www.mysite.com will redirect to mysite.com:8000, and then I set up my router to forward port 8000 to my server running nginx. This gets around my ISP's block on port 80. I'm now attempting to have nginx on the server proxy the request on port 8000 to a virtual host on port 80, so that the site will show up as mysite.com after it loads rather than mysite.com:8000.

I've been trying to do this with nginx's proxy_pass directive, but no matter what I do the site always shows up as mysite.com:8000.

Here's what I have so far:

server {
  listen [::]:8000

  server_name mysite.com;

  location / {
    proxy_pass http://127.0.0.1:80;
    proxy_redirect default;
    proxy_set_header  Host               $http_host;
    proxy_set_header  X-Real-IP          $remote_addr;
    proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto  http;
  }
 }

server {
  listen 127.0.0.1:80;

  server_name mysite.com;

  root /var/www/homepage;
  index index.html;

  .
  .  (non-relevant stuff)
  .
}

Link to the actual site: http://www.bjacobel.com

I've also tried to do this by forwarding port 8000 at the router to port 80, and having nginx listen on port 80, but the url with :8000 in it still shows up.

Thanks for your help!

回答1:

The root of the problem is not with your setup, but with the first web forward - it works by redirecting the requested URL (http://www.yoursite.com) to the new URL (http://yoursite.com:8000)

So this is already in place, when the request reaches your setup, and you can't change it back to port 80, as your provider blocks it.

You could use a frameset as a forwarder ("Web 0.5") or live with it.



回答2:

Word of warning, hosting public web servers on a residential connection is normally against the ISPs Terms Of Service.

The browser will always show 8080 because the HTTP connection needs to be initiated on port 8080 to access your site. Just think of the security issues if you could "hide" part of the URL.

The only workaround is to host a proxy server or a framed website on a server that can be accessed on port 80. Also, there are redirection services that could redirect port 80 to 8080.