一、前言#
- 正向代理功能比较简单,但是原生nginx不支持https代理,如果访问https网站,会报错。
Copy
# nginx代理不支持http CONNECT方法:
curl: (56) Received HTTP code 400 from proxy after CONNECT
二、下载并安装openresty#
Copy
shell> yum -y install lua-devel
shell> wget http://dlsw.91donkey.com/software/source/nginx/openresty-1.15.8.1.tar.gz
shell> wget http://dlsw.91donkey.com/software/source/nginx/ngx_http_proxy_connect_module.tgz && tar zxf ngx_http_proxy_connect_module.tgz
shell> tar zxf openresty-1.15.8.1.tar.gz
shell> vim bundle/nginx-1.15.8/auto/cc/gcc
# 将下列代码注释掉,能够减少编译后nginx二级制文件的大小,提高程序执行效率。
# debug
CFLAGS="$CFLAGS -g"
shell> cd openresty-1.15.8.1
shell> ./configure --prefix=/opt/openresty --with-http_stub_status_module --with-http_sub_module \
--with-http_auth_request_module --with-http_addition_module \
--add-module=/usr/local/src/ngx_http_proxy_connect_module
shell> patch -d build/nginx-1.15.8/ -p 1 < /usr/local/src/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch
shell> gmake -j 8 && gmake install
shell> echo "/opt/openresty/nginx/sbin/nginx" >> /etc/rc.d/rc.local
shell> /opt/openresty/nginx/sbin/nginx
三、配置服务器端nginx正向代理#
Copy
server {
listen 8080;
resolver 8.8.8.8;
resolver_timeout 5s;
proxy_connect;
proxy_connect_allow 443 563;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
location / {
proxy_pass $scheme://$host$request_uri;
proxy_set_header Host $http_host;
proxy_buffers 256 4k;
proxy_max_temp_file_size 0;
proxy_connect_timeout 30;
}
access_log /export/home/logs/proxy/access.log main;
error_log /export/home/logs/proxy/error.log;
}
四、配置终端代理#
Copy
export proxy="http://{proxy_server_ip}:8080"
export http_proxy=$proxy
export https_proxy=$proxy
shell> source /etc/profile
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器