nginx正向代理(nginx正向https代理配置)

 2025-08-13 13:03:02  阅读 390  评论 0

摘要:一、前言1.1 正向代理功能比较简单,但是原生nginx不支持https代理,如果访问https网站,会报错。# nginx代理不支持http CONNECT方法:
curl: (56) Received HTTP code 400 from proxy after CONNECT
1.2 为了实现对https代理的支持,需要对原有nginx源码打补丁,就可以让ngi

一、前言

1.1 正向代理功能比较简单,但是原生nginx不支持https代理,如果访问https网站,会报错。

# nginx代理不支持http CONNECT方法:
curl: (56) Received HTTP code 400 from proxy after CONNECT

1.2 为了实现对https代理的支持,需要对原有nginx源码打补丁,就可以让nginx支持CONNECT模式了。

https://github.com/chobits/ngx_http_proxy_connect_module#build-openresty

二、下载并安装openresty

shell> yum -y install lua-devel
shell> wget http://dlsw.91donkey.com/software/source/nginx/openresty-1.15.8.1.tar.gz
shell> git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
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 vim语法高亮
shell> cd /usr/local/src/openresty-1.11.2.5/build/nginx-1.11.2/contrib/vim/
shell> mkdir ~/.vim/ && \cp -R * ~/.vim/

三、配置服务器端nginx正向代理

# 在nginx.conf中增加server{}块,具体如下:
 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;
 }

四、配置终端代理

# 在 /etc/profile 文件中增加如下三项。
export proxy="http://{proxy_server_ip}:8080"
export http_proxy=$proxy
export https_proxy=$proxy
# 使配置生效
shell> source /etc/profile

作者:龍龍小宝

原文:https://www.cnblogs.com/91donkey/p/11639311.html

nginx正向https代理配置

版权声明:我们致力于保护作者版权,注重分享,被刊用文章【nginx正向代理(nginx正向https代理配置)】因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!;

原文链接:https://www.yxiso.com/zhishi/2092722.html

发表评论:

关于我们
院校搜的目标不仅是为用户提供数据和信息,更是成为每一位学子梦想实现的桥梁。我们相信,通过准确的信息与专业的指导,每一位学子都能找到属于自己的教育之路,迈向成功的未来。助力每一个梦想,实现更美好的未来!
联系方式
电话:
地址:广东省中山市
Email:beimuxi@protonmail.com

Copyright © 2022 院校搜 Inc. 保留所有权利。 Powered by BEIMUCMS 3.0.3

页面耗时0.0342秒, 内存占用1.91 MB, 访问数据库24次

陕ICP备14005772号-15