Nginx隐藏转发的端口号 [英] Nginx hide forwarded port number

查看:866
本文介绍了Nginx隐藏转发的端口号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个简单的静态网站,而nginx却存在一个问题,该问题因许多因素而变得复杂,最值得注意的是我的ISP阻止了所有入站端口80流量.

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.

首先,我进行了Web转发设置,以便www.mysite.com将重定向到mysite.com:8000,然后设置路由器以将端口8000转发到运行nginx的服务器.这绕过了我在端口80上的ISP的阻塞.我现在正在尝试让服务器上的nginx将端口8000上的请求代理到端口80上的虚拟主机,以便该站点在加载后会显示为mysite.com.比mysite.com:8000.

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.

我一直在尝试使用nginx的proxy_pass指令执行此操作,但是无论我做什么,该网站始终显示为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)
  .
}

链接到实际站点: http://www.bjacobel.com

我还尝试通过将路由器上的端口8000转发到端口80并让nginx监听端口80来做到这一点,但是其中仍带有:8000的url仍然显示.

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.

感谢您的帮助!

推荐答案

问题的根源不是您的设置,而是第一个网络转发-它通过将请求的URL( http://www.yoursite.com )重定向到新URL( http://yoursite.com:8000 )

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)

因此,当请求到达您的设置时,该位置已经到位,并且由于提供者阻止,您无法将其更改回端口80.

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.

您可以将框架集用作转发器("Web 0.5")或与之一起使用.

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

这篇关于Nginx隐藏转发的端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆