• nginx正向代理配置


    一、前言

    • 正向代理功能比较简单,但是原生nginx不支持https代理,如果访问https网站,会报错。
    # nginx代理不支持http CONNECT方法:
    curl: (56) Received HTTP code 400 from proxy after CONNECT
    

    二、下载并安装openresty

    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正向代理

    # 在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
    
  • 相关阅读:
    Docker配置容器位置和小技巧
    firewall防火墙
    iptables防火墙常用命令
    Docker 常用命令
    Dockerfile镜像的制作
    Windows和Centos下Docker的安装配置
    ubuntu 常用命令
    microPython环境安装及使用
    Arduino上“Collect2.exe: error: ld returned 5 exit status”错误的解决方法
    基于C语言的面向对象编程
  • 原文地址:https://www.cnblogs.com/91donkey/p/11639311.html
Copyright © 2020-2023  润新知