先记录一波正向代理
# make base image.
FROM debian:bookworm-20240423-slim AS base
LABEL maintainer="RocSun <[email protected]>"
RUN rm -rf /etc/apt/sources.list.d/* \
&& echo " " > /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
&& apt clean
FROM base AS pb
RUN apt update \
&& apt install -y --allow-downgrades libc6=2.36-9+deb12u4 libc-dev-bin=2.36-9+deb12u4 \
&& apt install -y build-essential zlib1g-dev libpcre3-dev libssl-dev unzip bzip2 automake pkg-config
# build source.
FROM pb AS build
ADD ./* /
RUN mkdir /nginx \
&& unzip -d /nginx/ /v0.0.6.zip \
&& mv /openssl-3.3.0 /nginx/ \
&& mv /pcre2-10.43 /nginx/ \
&& mv /zlib-1.3.1 /nginx/
RUN cd /nginx-1.24.0 \
&& patch -p1 < /nginx/ngx_http_proxy_connect_module-0.0.6/patch/proxy_connect_rewrite_102101.patch \
&& ./configure --prefix=/nginx --add-module=/nginx/ngx_http_proxy_connect_module-0.0.6 \
--with-pcre=/nginx/pcre2-10.43 \
--with-zlib=/nginx/zlib-1.3.1 \
--with-openssl=/nginx/openssl-3.3.0 \
--with-poll_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-stream \
&& make \
&& make install
WORKDIR /nginx
RUN rm -rf openssl-3.3.0 pcre2-10.43 zlib-1.3.1 ngx_http_proxy_connect_module-0.0.6
FROM base AS rt
COPY --from=build /nginx /nginx
ENV PATH=$PATH:/nginx/sbin
EXPOSE 80
EXPOSE 443
CMD [ "nginx", "-g", "daemon off;" ]
配置文件在/nginx/conf/
下。
重点正向代理配置:
server {
listen 1080;
resolver 8.8.8.8;
proxy_connect;
proxy_connect_allow 443 563;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
allow 192.168.1.0/24;
deny all;
proxy_pass http://$host;
proxy_set_header Host $host;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
全部配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
listen 1080;
resolver 8.8.8.8;
proxy_connect;
proxy_connect_allow 443 563;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
allow 192.168.1.0/24;
deny all;
proxy_pass http://$host;
proxy_set_header Host $host;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
标签:编译,nginx,connect,Nginx,html,proxy,http,Docker,location
From: https://www.cnblogs.com/linga/p/18193317