在网关中使用Nginx配置HTTP透明代理案例
出于某些需求在网关级架设HTTP透明代理,劫持用户HTTP请求,转发或直接进行响应。
iptables配置
iptables用于将经过网关的TCP80端口的上行流量转发至网关上的Nginx服务。
sudoiptables-tnat-APREROUTING-ptcp-mtcp--dport80-jDNAT\ --to-destination网关IP:端口
Nginx演示配置
worker_processes 1;
events{
worker_connections 1024;
}
http{
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server{
listen 8000;
server_name localhost;
resolver8.8.8.8;
location/test{
proxy_passhttp://hev.cc/sftp/files/;
proxy_buffers2564k;
proxy_max_temp_file_size0k;
}
location/{
#包含关键词'计算机'重定向至/test
rewrite^.*计算机.*$/testlast;
#通用透明代理
proxy_pass$scheme://$host$request_uri;
proxy_set_headerHost$http_host;
proxy_buffers2564k;
proxy_max_temp_file_size0k;
}
}
#匹配*.baidu.com域名
server{
listen 8000;
server_name *.baidu.com;
location/{
root html;
index index.htmlindex.htm;
}
}
}热门推荐
3 小托班祝福语简短
10 经典简短的祝酒祝福语
11 伴娘送亲祝福语简短精辟
12 周岁生日祝福语简短唯美
13 祝福语大全儿子结婚简短
14 订婚花束祝福语妈妈简短
15 新郎婚礼致辞祝福语简短
16 老总儿子生日祝福语简短
17 感谢室友毕业祝福语简短
18 精辟简短的公司祝福语