Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx hide forwarded port number [closed]

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!

like image 798
bjacobel Avatar asked Mar 16 '13 23:03

bjacobel


2 Answers

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.

like image 159
Eugen Rieck Avatar answered Sep 22 '22 05:09

Eugen Rieck


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.

like image 38
Steven V Avatar answered Sep 19 '22 05:09

Steven V