标签: reverse-proxy

1726
推荐指数
18
解决办法
55万
查看次数

从Docker容器内部,如何连接到本机的本地主机?

所以我在Docker容器中运行了一个Nginx,我在localhost上运行了一个mysql,我想从我的Nginx中连接到MySql.MySql在localhost上运行,而不是将端口暴露给外部世界,所以它绑定在localhost上,而不是绑定在机器的ip地址上.

有没有办法从这个docker容器中连接到这个MySql或localhost上的任何其他程序?

reverse-proxy nginx docker docker-networking

1176
推荐指数
24
解决办法
65万
查看次数

使用express.js代理

为了避免同域AJAX问题,我希望我的node.js Web服务器将所有请求从URL转发/api/BLABLA到另一个服务器,例如other_domain.com:3000/BLABLA,并且透明地向用户返回该远程服务器返回的相同内容.

所有其他URL(旁边/api/*)将直接提供,不代理.

如何使用node.js + express.js实现此目的?你能给出一个简单的代码示例吗?

(Web服务器和远程3000服务器都在我的控制之下,都运行带有express.js的node.js)


到目前为止,我发现了这个https://github.com/nodejitsu/node-http-proxy/,但阅读那里的文档并没有让我更聪明.我结束了

var proxy = new httpProxy.RoutingProxy();
app.all("/api/*", function(req, res) {
    console.log("old request url " + req.url)
    req.url = '/' + req.url.split('/').slice(2).join('/'); // remove the '/api' part
    console.log("new request url " + req.url)
    proxy.proxyRequest(req, res, {
        host: "other_domain.com",
        port: 3000
    });
});
Run Code Online (Sandbox Code Playgroud)

但没有任何东西返回原始的Web服务器(或最终用户),所以没有运气.

proxy reverse-proxy node.js express

148
推荐指数
7
解决办法
12万
查看次数

Nginx反向代理导致504网关超时

我使用Nginx作为反向代理,接受请求,然后执行proxy_pass从端口8001上运行的上游服务器获取实际的Web应用程序.

如果我去mywebsite.com或做一个wget,我会在60秒后获得504网关超时...但是,如果我加载mywebsite.com:8001,应用程序会按预期加载!

因此有些事情阻止了Nginx与上游服务器的通信.

所有这一切都是在我的托管公司重置机器运行之后开始的,之前没有任何问题.

这是我的vhosts服务器块:

server {
    listen   80;
    server_name mywebsite.com;

    root /home/user/public_html/mywebsite.com/public;

    access_log /home/user/public_html/mywebsite.com/log/access.log upstreamlog;
    error_log /home/user/public_html/mywebsite.com/log/error.log;

    location / {
        proxy_pass http://xxx.xxx.xxx.xxx:8001;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
} 
Run Code Online (Sandbox Code Playgroud)

我的Nginx错误日志输出:

2014/06/27 13:10:58 [error] 31406#0: *1 upstream timed out (110: Connection timed out) while connecting to upstream, client: xxx.xx.xxx.xxx, server: mywebsite.com, request: "GET / HTTP/1.1", upstream: "http://xxx.xxx.xxx.xxx:8001/", host: "mywebsite.com"
Run Code Online (Sandbox Code Playgroud)

reverse-proxy nginx proxypass http-status-code-504

103
推荐指数
6
解决办法
16万
查看次数

SSL握手期间与远程服务器出错

Apache2(正在听443)和一个运行的网络应用程序Tomcat7(在8443上收听)Ubuntu.

我将apache2设置为反向代理,以便通过端口443而不是8443访问Web应用程序.此外,我需要在浏览器和apache2之间以及apache2和tomcat7之间进行SSL通信,因此我在apache2和tomcat7上都设置了SSL .如果我尝试通过直接联系tomcat7来访问Web应用程序,一切都很好.问题是当我尝试通过apache2(反向代理)访问tomcat的web应用程序时,在浏览器上出现错误:

Proxy Error
The proxy server could not handle the request GET /web_app.
Reason: Error during SSL Handshake with remote server
Run Code Online (Sandbox Code Playgroud)

apache ssl tomcat reverse-proxy

101
推荐指数
2
解决办法
12万
查看次数

API网关与反向代理

为了处理微服务架构,它通常与反向代理(例如nginx或apache httpd)一起使用,并且对于交叉关注问题,使用实现 API网关模式.有时反向代理执行API网关的工作.
很高兴看到这两种方法之间存在明显的差异.看起来API网关使用的潜在好处是调用多个微服务并聚合结果.API网关的所有其他职责可以使用反向代理实现.例如:

  • 身份验证(可以使用nginx LUA脚本完成);
  • 运输安全.它本身就是反向代理任务;
  • 负载均衡
  • ....

基于此,有几个问题:

  1. 是否有意义地同时使用API​​网关和反向代理(例如请求 - > Api网关 - >反向代理(nginx) - >具体的mictoservice)?在什么情况下?
  2. 使用API​​网关可以实现的其他差异是什么,反向代理无法实现,反之亦然?

reverse-proxy nginx microservices aws-api-gateway tyk

85
推荐指数
3
解决办法
3万
查看次数

如何使用NGINX直接提供所有现有静态文件,但将其余部分代理到后端服务器.

location / {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    if (-f $request_filename) {
        access_log off;
        expires 30d;
        break;
        }

    if (!-f $request_filename) {
        proxy_pass http://127.0.0.1:8080; # backend server listening
        break;
        }
    }
Run Code Online (Sandbox Code Playgroud)

上面将使用Nginx直接提供所有现有文件(例如Nginx只显示PHP源代码),否则将请求转发给Apache.我需要从规则中排除*.php文件,以便*.php的请求也传递给Apache并进行处理.

我希望Nginx处理所有静态文件和Apache来处理所有动态的东西.

编辑:有白名单的方法,但它不是很优雅,看到所有这些扩展,我不希望这样.

location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
    access_log off;
    expires 30d;
    }
location / {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:8080;
    }
Run Code Online (Sandbox Code Playgroud)

编辑2:在使用nginx的更新版本try_files,而不是http://wiki.nginx.org/HttpCoreModule#try_files

reverse-proxy nginx static-files

76
推荐指数
3
解决办法
11万
查看次数

nginx - 从上游服务器读取自定义标头

我使用nginx作为反向代理,并尝试从上游服务器(Apache)的响应中读取自定义标头,但没有成功.Apache响应如下:

HTTP/1.0 200 OK
Date: Fri, 14 Sep 2012 20:18:29 GMT 
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.10
Connection: close
Content-Type: application/json; charset=UTF-8
My-custom-header: 1
Run Code Online (Sandbox Code Playgroud)

我想从My-custom-header读取值并在if子句中使用它:

location / {
    // ...
    // get My-custom-header value here
    // ...
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?提前致谢.

reverse-proxy nginx

65
推荐指数
4
解决办法
8万
查看次数

X-Forwarded-For 和 X-Real-IP 标头之间的差异

我使用 Nginx 作为反向代理。

这些标头有什么区别:

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP       $remote_addr;
Run Code Online (Sandbox Code Playgroud)

在一些文档/教程中,我看到两者都被使用,而在其他文档/教程中,只有第一个。

它们看起来很相似,所以我想了解它们有何不同以及我是否需要同时使用两者。

reverse-proxy http nginx http-headers nginx-reverse-proxy

51
推荐指数
1
解决办法
5万
查看次数

HAProxy + WebSocket断开连接

我正在使用HAProxy将子域上的请求发送到node.js应用程序.

我无法让WebSockets工作.到目前为止,我只能让客户端建立WebSocket连接,但之后很快就会出现断开连接.

我在ubuntu上.我一直在使用的各种版本socket.ionode-websocket-server.客户端是Safari或Chrome的最新版本.HAProxy版本是1.4.8

这是我的HAProxy.cfg

global 
    maxconn 4096 
    pidfile /var/run/haproxy.pid 
    daemon 

defaults 
    mode http 

    maxconn 2000 

    option http-server-close
    option http-pretend-keepalive

    contimeout      5000
    clitimeout      50000
    srvtimeout      50000

frontend HTTP_PROXY
    bind *:80 

    timeout client  86400000

    #default server
    default_backend NGINX_SERVERS

    #node server
    acl host_node_sockettest hdr_beg(host) -i mysubdomain.mydomain

use_backend NODE_SOCKETTEST_SERVERS if host_node_sockettest


backend NGINX_SERVERS 
server THIS_NGINX_SERVER 127.0.0.1:8081

backend NODE_SOCKETTEST_SERVERS
timeout queue   5000
timeout server  86400000

server THIS_NODE_SERVER localhost:8180 maxconn 200 check
Run Code Online (Sandbox Code Playgroud)

我已经浏览了网络和邮件列表但无法获得任何建议的解决方案.

(ps这可能是针对serverfault,但是还有其他的HAProxy问题,所以我选择在这里发帖)

reverse-proxy haproxy websocket node.js

43
推荐指数
3
解决办法
4万
查看次数