在网关中使用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;
}
}
}热门推荐
10 郑伊健结婚祝福语简短高级
11 宝宝新生入学祝福语简短
12 老爸六十生日祝福语 简短
13 M退休祝福语结婚简短
14 信件告别祝福语大全简短
15 蛋糕祝老师祝福语简短
16 学校职工祝福语大全简短
17 项目部新年祝福语简短
18 结婚见证祝福语简短精辟