Using nginx to build a public network proxy server


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
git clone
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…

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;
#DNS server IP or internet gateway IP
    server {
        listen 6666;
        #Proxy port        
        #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


to configure:

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



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


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


Docker service overload:

 systemctl daemon-reload
 systemctl restart docker


 systemctl show --property=Environment docker  

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

:kissing_ closed_ eyes: