月份:2021年6月
nginx 作为正向代理
nginx还是蛮强大的,不仅可以作为7层的正向代理,还可以作为4层的正向代理。
参考文档 https://zhuanlan.zhihu.com/p/70522194
7层是需要加三分模块 ngx_http_proxy_connect_module,github地址:https://github.com/chobits/ngx_http_proxy_connect_module 注意,不同的Nginx版本,还需要下载不同的patch包
具体配置 参考 https://github.com/aminglinux/nginx/blob/master/proxy/z_proxy.md
配置文件
server {
listen 3128;
# dns resolver used by forward proxying
resolver 119.29.29.29;
# forward proxy for CONNECT request
proxy_connect;
proxy_connect_allow 80 443 8080;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
# forward proxy for non-CONNECT request
location / {
proxy_pass http://$host;
proxy_set_header Host $host;
}
}
4层的话,需要额外增加编译参数
--with-stream --with-stream_ssl_preread_module --with-stream_ssl_module
配置文件
stream {
resolver 114.114.114.114;
server {
listen 443;
ssl_preread on;
proxy_connect_timeout 5s;
proxy_pass $ssl_preread_server_name:$server_port;
}
}
Nginx记录用户请求Header到access log
2021年6月18日
未分类
No Comments
aming
参考 https://www.cnblogs.com/Serverlessops/p/13410262.html
log_format里增加字段: “$http_mycheck“‘
curl -H “mycheck: justtestlog” localhost/whatever.html