Proxy servers and tunneling

当访问不同的网站时,代理服务器和HTTP管道帮助访问万维网 . 一个代理可以是用户的本地计算机,或者介于用户计算机和终端服务器之间的地方。本章节概述一些关于代理和相关配置选项的基础知识。

有两种代理: 正向代理 (如:管道、网关) 和反向代理 (用于控制和保证服务器的负载均衡、认证、加密和缓存)。

正向代理

正向代理, 也可以叫“网关” 或者仅仅为一个或多个客户端提供代理服务的“代理”。在互联网上像这样的代理不计其数。 他们存储并转发网络服务(如DNS,网页)以减少和控制大家所使用的带宽。

正向代理可以是匿名代理,并允许用户在浏览web或者使用其他服务时隐藏自己的IP。 TOR (洋葱路由), 匿名地在多个代理间路由因特网。

Reverse proxies

As the name implies, a reverse proxy does the opposite of what a forward proxy does: A forward proxy acts in behalf of clients (or requesting hosts), a reverse proxy acts in behalf of servers. Forward proxies can hide the identities of clients whereas reverse proxies can hide the identities of servers. Reverse proxies have several use cases, a few are:

  • Load balancing: distribute the load to several web servers,
  • Cache static content: offload the web servers by caching static content like pictures,
  • Compression: compress and optimize content to speed up load time.

Forwarding client information through proxies

Proxies can make requests appear as if they originated from the proxy's IP address. This can be useful if a proxy is used to provide client anonymity, but in other cases information from the original request is lost. The IP address of the original client is often used for debugging, statistics, or generating location-dependent content. A common way to disclose this information is by using the following HTTP headers:

The standardized header:

Forwarded
Contains information from the client-facing side of proxy servers that is altered or lost when a proxy is involved in the path of the request.

Or the de-facto standard versions:

X-Forwarded-For
Identifies the originating IP addresses of a client connecting to a web server through an HTTP proxy or a load balancer.
X-Forwarded-Host
Identifies the original host requested that a client used to connect to your proxy or load balancer.
X-Forwarded-Proto
identifies the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer.

To provide information about the proxy itself (not about the client connecting to it), the Via header can be used.

Via
Added by proxies, both forward and reverse proxies, and can appear in the request headers and the response headers.

HTTP tunneling

Tunneling transmits private network data and protocol information through public network by encapsulating the data. HTTP tunneling is using a protocol of higher level (HTTP) to transport a lower level protocol (TCP).

The HTTP protocol specifies a request method called CONNECT. It starts two-way communications with the requested resource and can be used to open a tunnel. This is how a client behind an HTTP proxy can access websites using SSL (i.e. HTTPS, port 443). Note, however, that not all proxy servers support the CONNECT method or limit it to port 443 only.

See also the HTTP tunnel article on Wikipedia.

Proxy Auto-Configuration (PAC)

A Proxy Auto-Configuration (PAC) file is a JavaScript function that determines whether web browser requests (HTTP, HTTPS, and FTP) go directly to the destination or are forwarded to a web proxy server. The JavaScript function contained in the PAC file defines the function:

The auto-config file should be saved to a file with a .pac filename extension:

proxy.pac

And the MIME type set to:

application/x-ns-proxy-autoconfig

The file consists of a function called FindProxyForURL. The example below will work in an environment where the internal DNS server is set up so that it can only resolve internal host names, and the goal is to use a proxy only for hosts that aren't resolvable:

function FindProxyForURL(url, host) {
  if (isResolvable(host))
    return "DIRECT";
  else
    return "PROXY proxy.mydomain.com:8080";
}

See Proxy Auto-Configuration (PAC) for more examples.

See also