首页 > 系统相关 >Docker 编译安装Nginx正向代理

Docker 编译安装Nginx正向代理

时间:2024-05-15 10:30:02浏览次数:21  
标签:编译 nginx connect Nginx html proxy http Docker location

先记录一波正向代理

# 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

相关文章

  • docker搭建Elasticsearch、Kibana、Logstash 同步mysql数据到ES
    一、前言在数据量大的企业级实践中,Elasticsearch显得非常常见,特别是数据表超过千万级后,无论怎么优化,还是有点力不从心!使用中,最首先的问题就是怎么把千万级数据同步到Elasticsearch中,在一些开源框架中知道了,有专门进行同步的!那就是Logstash。在思考,同步完怎么查看呢,这时Kibana映入......
  • Docker安装Rabbitmq
    step1:安装必要的一些系统工具yuminstall-yyum-utilsdevice-mapper-persistent-datalvm2Step2:添加软件源信息yum-config-manager--add-repohttps://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoStep3:更新并安装Docker-CEyummakecachefasty......
  • ubuntu系统 设置docker以及容器开机 启动
     一、Docker服务设置开机启动docker设置开机启动systemctlenabledocker.servicedocker关闭开机启动systemctldisabledocker.service重新设置docker在系统中的自启动systemctlreenabledocker.service 二、Docker服务设置开机启动启动时加......
  • Unraid 使用 Docker Compose 安装 Immich 套件无法启用人脸识别的原因及修复方法
    原因问题原因是官方教程中的docker-compose.yml指明的机器学习组件immich-machine-learning中的container_name也就是docker-compose.yml中不同service可以互访的媒介hostname与immich-server默认设置中的机器学习服务器url的hostname不匹配造成的。解决方法......
  • docker——health(容器的健康检查)
    容器的健康检查机制了解在dockerfile中容器的健康检查#在dockerfile中使用healthcheck指令,声明健康检测配置,用于判断容器主进程的服务状态是否正常,反映容器的实际健康状态。基于这样的dockerfile构建镜像,在基于该镜像启动容器,这样的容器就具备健康状态。能够自动进行健康检查。......
  • nginx实用入门
    下载并启动下载地址:http://nginx.org/en/download.html双击即可启动测试启动:http://localhost/部署网站添加该条配置即可server{listen8088;server_name名字;location/{root文件目录;indexindex.htmlindex.htm;}}关闭、开始、重启在cmd下操作,进......
  • 离线安装docker,并导入镜像文件
    在Ubuntu20.04系统上离线安装Docker,并导入Redis镜像,需要分几个步骤进行。以下是详细的步骤:1.离线下载Docker安装包首先,你需要在有网络连接的机器上下载Docker的.deb安装包以及其依赖项。下载Docker.deb包和依赖项在联网的机器上:创建一个目录来存放所有的.deb文件:mkdi......
  • XeLaTeX 无法编译含有经过 pdfcrop 裁剪的 PDF 文件的文档
    今天在写LaTeX文档时踩了个大坑,我在文档里插入了一个PDF图片之后文档无法编译了。于是我去掉多余代码,做了一个最小工作示例:\documentclass{article}\usepackage{graphicx}\begin{document}\includegraphics{my_image.pdf}\end{document}就是这样一个简单的代码,pdfLa......
  • k8s——configmap-secret-nginx实验
    简介configmapsecret一、实验环境二、实验描述三、实验1:步骤1.使用configmap投射到nginx.conf配置文件到pod里1.1需要准备nginx.conf配置文件1.2将nginx.conf内容存放到configmap里(通过文件的方式,,这样简单一点)1.3启动ngnix的pod,使用configmap里的nginx.conf配置文件2.......
  • 关于编译的一些debug记录
    1.背景:现在想将嵌入式开发板部署成边缘控制器,需要在开发板上部署一个服务。我们已经写了一个c语言的应用,现在需要将其编译成适配64位arm架构的2进制可执行文件2.bug:在编译的时,输入命令:g++-fdiagnostics-color=always-gunifiedAccessServer.cppbaseModels/control/ec/ec......