转自:http://blog.csdn.net/longmarch12/article/details/6563820
nginx是一款强大的反向代理服务器软件,除了作为http服务器和反向代理之外,还可以架设http代理服务器。
配置很简单:
- resolver YOUR_RESOLV_IP;
- server {
- listen proxy_ip:proxy_port;
- location / {
- proxy_pass http://$http_host$request_uri;
- access_log logs/http_proxy.access.log;
- error_log logs/http_proxy.error.log;
- }
- }
=========================================================
wget通过http代理访问:
在服务器上wget之前,设置一下环境变量:
export http_proxy=proxy_ip:proxy_port
wget http://www.qq.com
--16:25:38-- http://www.qq.com/
=> `index.html'
Connecting to proxy_ip:proxy_port... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
[ <=> ] 55,822 121.90K/s
16:25:42 (121.74 KB/s) - `index.html' saved [55822]
大功告成。
===============================================
PHP中如何使用代理发送http请求呢?
一、 使用CURL扩展
- $curl = curl_init($url); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);curl_setopt($ch, CURLOPT_PROXY, 'proxy_ip:proxy_port');$res = curl_exec($curl);
二、 使用pecl的http扩展
官网地址:http://pecl.php.net/package/pecl_http
使用方式:
- $http_obj = new HttpRequest($url, HttpRequest::METH_GET); $options = array( 'useragent' => 'Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1', 'connecttimeout' => 1, 'timeout' => 3, 'proxyhost' => 'proxy_ip:proxy_port ',); $http_obj->setOptions($options); $message_obj = $this->mHTTP->send();$res = $message_obj->getBody();