通过ssh隧道和nginx代理访问服务器

我是nginx的新手。 我已经用nginxinheritance了一个function齐全的configuration好的Ubuntu服务器,并且希望另外调整它来支持下面描述的有点奇怪的configuration。

基本信息。 我的Ubuntu服务器(我们将其命名为server.corp.com)运行在内部公司networking中。 它拥有Gerrit和Jenkins,每个都有www接口,在自己的端口(8081和8082)上侦听,nginx代理请求到相应的locations 。 例如http://server.corp.com/gerrit的请求被代理到http://server.corp.com:8081不幸的是,我现在无法显示nginxconfiguration,因为我正在家里写这个问题。 我记得它包含了带有proxy_pass子句的行。

现在,这是奇怪的configuration。

 server.corp.com, ports 80, 22 and 29418 <--> other Linux <--> Windows 

Other Linux和Windows PC也属于公司networking(很大)。 Other Linux可以通过端口80,22和29418连接到我的服务器。其他端口被防火墙阻止,我不会受到影响。 Windows PC可以使用SSH连接到Other Linux ,并且可能还有其他端口和协议。 我在Other Linux上既没有login也没有超级用户权限。

我的同事WindowsPC用户已经成功地在端口29418上使用Putty和SSH隧道连接到我们的Gerrit(它也监听端口29418)。 相应的隧道是localhost:29418 -> server.corp.com:29418

我的目标是让我的同事在server.corp.com访问Gerrit和Jenkins的www接口。

我可以指示他build立一个或多个SSH隧道到我的服务器。 不过,我想,这也需要一些调整nginx,因为简单的SSH隧道localhost:80 -> server:80不起作用。 Chrome在尝试连接到本地主机时抱怨SSL连接超时:80。

更新2:我试图在我的电脑上build立这个设置(Windows也是如此),并使用Gi​​t发行版中的wget。 我还创build了一个实验的位置。

这里是nginxconfiguration的相关部分(我希望)

 # file nginx.conf include /etc/nginx/conf.d/*.conf; # ... # file conf.d/tunnel.conf # This server clause is contained in conf.d/tunnel.conf server { listen 80; server_name "localhost:1234" xxx.xxx.xxx.xxx; server_name_in_redirect off; location /gerrit2 { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:8081; } } # end of tunnel.conf # again, file nginx.conf server { listen 80 default; rewrite ^ http://server.corp.com$request_uri permanent; } server { listen 80; server_name server.corp.com; location ~ "^/$" { rewrite / /redmine; } location /gerrit/ { proxy_pass http://localhost:8081; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; } } 

wget -d的输出如下:

 $ wget -d http://localhost:1234/gerrit2 DEBUG output created by Wget 1.11.4 on Windows-MSVC. --2015-11-12 11:20:51-- http://localhost:1234/gerrit2 Resolving localhost... seconds 0.00, 127.0.0.1 Caching localhost => 127.0.0.1 Connecting to localhost|127.0.0.1|:1234... seconds 0.00, connected. Created socket 900. Releasing 0x029773e8 (new refcount 1). ---request begin--- GET /gerrit2 HTTP/1.0 User-Agent: Wget/1.11.4 Accept: */* Host: localhost:1234 Connection: Keep-Alive ---request end--- HTTP request sent, awaiting response... ---response begin--- HTTP/1.1 301 Moved Permanently Server: nginx/1.4.6 (Ubuntu) Date: Thu, 12 Nov 2015 08:20:51 GMT Content-Type: text/html Content-Length: 193 Connection: keep-alive Location: http://server.corp.com/gerrit2 ---response end--- 301 Moved Permanently Registered socket 900 for persistent reuse. Location: http://server.corp.com/gerrit2 [following] Skipping 193 bytes of body: [<html> <head><title>301 Moved Permanently</title></head> <body bgcolor="white"> <center><h1>301 Moved Permanently</h1></center> <hr><center>nginx/1.4.6 (Ubuntu)</center> </body> </html> ] done. --2015-11-12 11:20:51-- http://server.corp.com/gerrit2 Resolving server.corp.com... seconds 0.00, xxx.xxx.xxx.xxx Caching server.corp.com => xxx.xxx.xxx.xxx Connecting to server.corp.com|xxx.xxx.xxx.xxx|:80... seconds 0.00, connected. Created socket 896. Releasing 0x02977428 (new refcount 1). ---request begin--- GET /gerrit2 HTTP/1.0 User-Agent: Wget/1.11.4 Accept: */* Host: server.corp.com Connection: Keep-Alive ---request end--- HTTP request sent, awaiting response... ---response begin--- HTTP/1.1 404 Not Found Server: nginx/1.4.6 (Ubuntu) Date: Thu, 12 Nov 2015 08:20:51 GMT Content-Type: text/html Content-Length: 177 Connection: keep-alive ---response end--- 404 Not Found Disabling further reuse of socket 900. Closed fd 900 Registered socket 896 for persistent reuse. Skipping 177 bytes of body: [<html> <head><title>404 Not Found</title></head> <body bgcolor="white"> <center><h1>404 Not Found</h1></center> <hr><center>nginx/1.4.6 (Ubuntu)</center> </body> </html> ] done. 2015-11-12 11:20:51 ERROR 404: Not Found. 

find解决scheme 一个需要添加到主机

 127.0.0.1 server.corp.com