• docker部署nginx+反向代理配置/代理宿主机网段服务器


    1、安装docker,并运行

    2、拉取nginx镜像

    docker pull nginx
    
    • 1

    3、运行nginx容器,将文件拷贝至本地,并将nginx容器删除

    #运行nginx容器

    docker run -id --name mynginx -p 8080:80 nginx
    
    • 1

    #将配置文件从容器内拷贝至本地

    docker cp 容器ID:/etc/nginx/nginx.conf /data01/nginx/
    docker cp 容器ID:/usr/share/nginx/html /data01/nginx/
    
    • 1
    • 2

    #将容器删除

    docker stop 容器ID
    docker rm 容器ID
    
    • 1
    • 2

    4、运行生产nginx,并将宿主机IP用作容器IP,不单独进行IP分配

    docker run -id --name mynginx --net host -v /data01/nginx/nginx.conf:/etc/nginx/nginx.conf -v /data01/nginx/conf.d:/etc/nginx/conf.d nginx
    
    • 1

    5、配置反向代理模板,重启容器生效

    vim zabbix.conf
    	server {
        listen 8110;
        #server_name zabbix.test.com;
    
        access_log /var/log/nginx/zabbix.access.log;
        error_log  /var/log/nginx/zabbix.error.log;
    
        location / {
                proxy_pass http://10.175.246.31;
                #proxy_http_version 1.1;
                #proxy_buffering off;
                #proxy_request_buffering off;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Cookie $http_cookie;
                #proxy_redirect off;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    6、验证

    [root@dock-appla01 /]# netstat -tunlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 0.0.0.0:8110            0.0.0.0:*               LISTEN      19558/nginx: master 
    tcp        0      0 0.0.0.0:8111            0.0.0.0:*               LISTEN      19558/nginx: master 
    tcp        0      0 0.0.0.0:8112            0.0.0.0:*               LISTEN      19558/nginx: master 
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      27419/sshd 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  • 相关阅读:
    HIVE高级调优(四)
    剑指offer57-61排序-堆
    12.JVM
    ctfshow web七夕杯
    RHCE---作业3
    金融行业数智化供应链管理系统:多维度评估分析供应商,赋能智能金融变革
    element ui,node-sass 安装出错,绝对能解决
    常用API类及异常体系
    分享个包含各省、市、区的编码数据的在线静态资源脚本
    c++ goto语句
  • 原文地址:https://blog.csdn.net/python10101/article/details/136407242