# nginx tar包下载地址 http://nginx.org/download/ 先说nginx正向代理配置:
server { listen 3128; # dns resolver used by forward proxying resolver 114.114.114.114; # forward proxy for CONNECT requests proxy_connect; proxy_connect_allow 443 563; proxy_connect_connect_timeout 10s; proxy_connect_data_timeout 10s; # defined by yourself for non-CONNECT requests # Example: reverse proxy for non-CONNECT requests location / { proxy_pass http://$host; proxy_set_header Host $host; } }由于默认的nginx发布版本不支持正向代理功能,需要借助ngx_http_proxy_connect_module这个三方插件来完成,具体步骤如下 ngx_http_proxy_connect_module下载地址:https://github.com/chobits/ngx_http_proxy_connect_module 1、下载nginx源码包,笔者使用的是1.19.10版本,具体下载地址为:http://nginx.org/download/ 2、安装依赖组件,sudo install openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev 3、下载ngx_http_proxy_connect_module三方组件源码 4、执行命令 注意版本选择
注意这个patch命令的用法,-p1 : 1代表跳过的层级数字
patch -p1 < /opt/nginx_tar/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1021.patch5、执行configure命令
./configure --add-module=/opt/nginx_tar/ngx_http_proxy_connect_module6、执行make & make install进行编译及安装(如果是yum安装好的,不要再make install, make好后,先测试下,没问题,再替换nginx执行文件) 7、编译成功后会把nginx放在/usr/local/nginx目录下,其他目录参照nginx官网http://nginx.org/en/docs/configure.html 8、找到nginx的配置文件,默认为/usr/local/nginx/conf目录,添加如下配置: 9. 简单测试: curl -i https://www.163.com -v -x x.x.132.46:12880 二、服务器配置proxy几种方式: 在centos里面配置全局代理,任何出去都走代理 如果只是测试下可以用curl -x或--proxy 代理i:port
export http_proxy='x.x.132.46:12880' # http export https_proxy='x.x.132.46:12880' # https 以上永久生效,需要写在/etc/profile中,或/etc/profile.d/proxy.sh [root@sz-d-test-07 ~]# echo $http_proxy 10x.x5.136.51:8000 [root@sz-d-test-07 ~]# echo $https_proxy 10x.x5.136.51:8000 [root@sz-d-test-07 ~]#
1. centos全局代理配置:
export http_proxy='x.x.132.46:12880' # http export https_proxy='x.x.132.46:12880' # https source /etc/profile # test echo $http_proxy #或者干脆全局都使用 export ALL_PROXY='x.x.132.46:12880'2. yum的代理设置:
vi /etc/yum.conf # proxy = http://username:password@yourproxy:port/ 或者 proxy=http://yourproxy:port proxy=ftp://yourproxy:port proxy_username=username proxy_password=password3. wget的代理设置
vi /etc/wgetrc #添加下面内容 #Proxy http_proxy=http://username:password@proxy_ip:port/ ftp_proxy=http://username:password@proxy_ip:port/要想不用proxy,需要把配置删掉,同时重启服务器,才能生效!!单纯的source /etc/profile好像不生效 标签:http,代理,module,nginx,connect,https,正向,proxy From: https://www.cnblogs.com/macoffee/p/17932330.html