Using nginx to build a public network proxy server

Time:2022-5-11

Using nginx to build a public network proxy server

1. Proxy nginx server installation

Nginx-1.16.0 is used here

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel patch  pcre pcre-devel
wget http://nginx.org/download/nginx-1.16.0.tar.gz
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
tar xf nginx-1.16.0.tar.gz -C /usr/local/src/
cd /usr/local/src/nginx-1.16.0/
patch -p1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch 
#Proxy here_ connect_ Module selection is related to nginx version
./configure --add-module=/root/ngx_http_proxy_connect_module/
make -j 4
#I have a 4-core CPU here
make install

Installation instructions:

1. Nginx forward proxy only supports HTTP by default,

2. HTTPS support needs to be realized with the help of the third-party module “ngx_http_proxy_connect_module”;

Module GitHub address:github.com/chobits/ngx_http_proxy_…

2. Proxy nginx server configuration

#cat /usr/local/nginx/conf/nginx.conf
worker_processes  4;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
resolver 114.114.114.114;
#DNS server IP or internet gateway IP
    server {
        listen 6666;
        #Proxy port        
        proxy_connect;
        #Call NGX_ http_ proxy_ connect_ Module module
        location / {
            proxy_pass $scheme://$host$request_uri;
        }
    }    
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass $scheme://$host$request_uri;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

3. The client configures the external network on the proxy server

3.1、Linux

to configure:

vim /root/. Bashrc #http & HTTPS proxy is configured into the user environment variable
export http_proxy=10.100.49.12:6666
export https_proxy=10.100.49.12:6666

Test:

curl  www.baidu.com
3.2、Docker

to configure:

mkdir -p /etc/systemd/system/docker.service.d
 vim /etc/systemd/system/docker. service. d/http-proxy. Conf # add HTTP proxy for editing docker

[Service]
 Environment="HTTP_PROXY=http://10.100.49.12:6666"

 vim /etc/systemd/system/docker. service. d/https-proxy. Conf # add HTTPS proxy for editing docker

 [Service]
 Environment="HTTPS_PROXY=http://10.100.49.12:6666"

Docker service overload:

 systemctl daemon-reload
 systemctl restart docker

Test:

 systemctl show --property=Environment docker  

This work adoptsCC agreement, reprint must indicate the author and the link to this article

:kissing_ closed_ eyes: